package seatechit.msbgateway.consumer;

import java.rmi.RemoteException;
import java.util.ArrayList;
import java.util.List;

import javax.xml.rpc.ServiceException;

import org.apache.log4j.Logger;

import seatechit.msbgateway.dbaccess.entity.AccountInfo;
import seatechit.msbgateway.dbaccess.entity.CurrencyInfo;
import seatechit.msbgateway.dbaccess.entity.CustomerInfo;
import seatechit.msbgateway.dbaccess.entity.HOSTMessagLogInfo;
import seatechit.msbgateway.dbaccess.entity.HostTranCodeInfo;
import seatechit.msbgateway.dbaccess.entity.ServiceInfo;
import seatechit.msbgateway.dbaccess.facade.AccountInfoFacade;
import seatechit.msbgateway.dbaccess.facade.CustomerInfoFacade;
import seatechit.msbgateway.proxy.as400gw.AS400_PortType;
import seatechit.msbgateway.proxy.as400gw.AS400_ServiceLocator;
import seatechit.msbgateway.proxy.as400gw.Messages;
import seatechit.msbgateway.utils.AppUtils;
import seatechit.msbgateway.utils.CachedParam;
import seatechit.msbgateway.utils.CoreBankUtils;
import seatechit.msbgateway.utils.ElementUtils;
import seatechit.msbgateway.utils.Global;

import com.ibm.broker.plugin.MbElement;
import com.ibm.broker.plugin.MbMessage;

/**
 * Main class process message send/receive to/from Silverlake corebank system
 * 
 * @author Vu Trung Kien
 * @version 1.0
 * @since 1.6
 * 
 */

public class SIBSConsumer extends BaseConsumer {
	final Logger logger = Logger.getLogger(SIBSConsumer.class);
	final String CLASS_NAME = this.getClass().getName();
	private AS400_ServiceLocator as400Service;
	protected AS400_PortType as400Port;
	protected Messages retMessage = null;
	protected String[] ABCS_TEMPLATE;
	protected HostTranCodeInfo hostTranCodeInfo = null;

	protected void initABCSMessageTemplate() {
		ABCS_TEMPLATE = new String[306];
		ABCS_TEMPLATE[0] = "4092";// Socket Message Length
		ABCS_TEMPLATE[1] = "*LINX";// Header Type
		ABCS_TEMPLATE[6] = "213";// Header Length
		ABCS_TEMPLATE[7] = "42";// Message Length
		ABCS_TEMPLATE[8] = "0200";// Version Number
		ABCS_TEMPLATE[10] = "ABCS";// Data Format ID
		ABCS_TEMPLATE[11] = "*LINX";// Source ID
		ABCS_TEMPLATE[31] = "3843";// APPLICATION DATA LENGTH
		ABCS_TEMPLATE[32] = "*MOSA";
		ABCS_TEMPLATE[39] = "T9999";
		ABCS_TEMPLATE[44] = "N";
		ABCS_TEMPLATE[51] = "VD";// CONTROL UNIT
		ABCS_TEMPLATE[52] = "vt";// WORK STN
		ABCS_TEMPLATE[55] = "0";// REBIT REQUEST NO
		ABCS_TEMPLATE[56] = "1";// AM/PM MODE
		ABCS_TEMPLATE[57] = "N";
		ABCS_TEMPLATE[58] = "N";
		ABCS_TEMPLATE[59] = "N";
		ABCS_TEMPLATE[60] = "N";
		ABCS_TEMPLATE[61] = "N";
		ABCS_TEMPLATE[62] = "N";
		ABCS_TEMPLATE[63] = "N";
	}

	protected String[] MBASE_TEMPLATE;

	protected void initMBASEMessageTemplate() {
		MBASE_TEMPLATE = new String[422];
		MBASE_TEMPLATE[0] = "680";
		MBASE_TEMPLATE[1] = "*LINX";
		MBASE_TEMPLATE[6] = "213";
		MBASE_TEMPLATE[8] = "0200";
		MBASE_TEMPLATE[9] = "*DSP";
		MBASE_TEMPLATE[10] = "MBSD";
		MBASE_TEMPLATE[11] = "*LINX";
		MBASE_TEMPLATE[15] = "01";
		MBASE_TEMPLATE[23] = "10";
		MBASE_TEMPLATE[24] = "10";
		MBASE_TEMPLATE[28] = "N";
		MBASE_TEMPLATE[33] = "1";
		MBASE_TEMPLATE[35] = "*END";
		MBASE_TEMPLATE[37] = "BTS";
		MBASE_TEMPLATE[38] = "RBS";
		MBASE_TEMPLATE[39] = "";
		MBASE_TEMPLATE[41] = "27";
		MBASE_TEMPLATE[47] = "I";
		MBASE_TEMPLATE[48] = "R";
		MBASE_TEMPLATE[49] = "10";
		MBASE_TEMPLATE[50] = "N";
		MBASE_TEMPLATE[51] = "F";
	}

	public SIBSConsumer() {
		super();
		try {
			initABCSMessageTemplate();
			initMBASEMessageTemplate();
			this.consumerType = Global.CONSUMER_CODE_SIBS;
			ServiceInfo objService = CachedParam.getServiceInfoByServiceType(consumerType);
			as400Service = new AS400_ServiceLocator();
			as400Service.setServiceTimeout(objService.getService_timeout() * 1000);
			as400Service.setAS400HttpPortEndpointAddress(objService.getService_url());
			as400Port = as400Service.getAS400HttpPort();
		} catch (ServiceException e) {
			e.printStackTrace();
		}
	}

	@Override
	public void submit(final MbMessage inMessage, MbMessage outMessage) {
		try {
			this.retErrorInfo.setErrorType(Global.MESSAGE_TYPE_OTHER);
			this.inMessage = inMessage;
			this.outMessage = outMessage;

			this.baseXmlRequestDoc = ElementUtils.getXMLContent(inMessage);
			this.buildLogOfRequestMessage();

			String tran_code = xmlMessageLogInfo.getTran_code();
			String tran_service_code = xmlMessageLogInfo.getTran_service_code();
			buildTransactionInfo(consumerType, tran_code, tran_service_code);

			// COMMON
			if (tran_code.equals(Global.MSG_CM_INQUIRY_CIF_INFOR)) {
				getCustomerInfoOffline();
				// getCustomerInfoOnline();
			} else if (tran_code.equals(Global.MSG_CM_INQUIRY_CIF_ACCOUNTS)) {
				getCustomerAccounts();
			} else if (tran_code.equals(Global.MSG_TR_TRANSFER_MONEY)) {
				fundTransfer();
			} else if (tran_code.equals(Global.MSG_OS_CREATE_FD_ACCOUNT)) {
				createFDAccount();
			} else if (tran_code.equals(Global.MSG_OS_CREATE_FD_RECEIPT)) {
				createFDReceipt();
			} else if (tran_code.equals(Global.MSG_OS_TRANSFER_FD_RECEIPT)) {
				transferToFDReceipt();
			} else if (tran_code.equals(Global.MSG_OS_SETTLEMENT_FD_ACCOUNT)) {
				settlementFDAccount();
			} else if (tran_code.equals(Global.MSG_LN_PAYMENT_LN_TRANSACTION)) {
				loanPayment();
			} else if (tran_code.equals(Global.MSG_CS_ACTIVATED_ATMCARD)) {
				activeATMCard();
			} else if (tran_code.equals(Global.MSG_TR_CREATE_CASHFLOW_TRANSACTION)) {
				createCashFlowOrder();
			} else if (tran_code.equals(Global.MSG_TR_CANCEL_CASHFLOW_TRANSACTION)) {
				cancelCashFlowOrder();
			} else if (tran_code.equals(Global.MSG_FX_CREATE_EXCHANGEMONEY_TRANSACTION)) {
				exchangeMoney();
			} else if (tran_code.equals(Global.MSG_CM_INQUIRY_MINISTATEMENT_BY_ACCOUNT)) {
				inquiryMiniStatement();
			} else {
			}

			// 3)add more detail response time,date....
			this.buildLogOfResponseMessage();
			this.xmlMessageLogInfo.setExecution_date(hostMessageLogInfo.getHost_tran_date());
			this.xmlMessageLogInfo.setRef_tran_no(hostMessageLogInfo.getHost_tran_sn());
			this.buildXMLMessageResponseHeader();
			this.baseXmlResponseDoc = ElementUtils.getXMLContent(outMessage);
			this.buildLogMessageInfo();
			this.logMessageFacade.insertLogMessage(logMessage);
		} catch (Exception ex) {
			ex.printStackTrace();
			logger.error(new StringBuffer().append("Error source:").append(CLASS_NAME + ".submit()\n").append("Error message:").append(ex.toString() + "\n"));
			this.retErrorInfo.setErrorCode(Global.ERR_SYSTEM_UNKNOWN_ERROR);
			this.retErrorInfo.setErrorMessage(ex.toString());

		}
	}

	/**
	 * (CM021)Query CIF information(use cif number or id card+mobile to get cif
	 * information)
	 * 
	 * @version 1.0
	 */
	private void getCustomerInfoOffline() {
		try {
			String xpathInput = "/message/body/field[@name='%s']";
			String cif_no = ElementUtils.getXMLElementInStringValue(inMessage, String.format(xpathInput, "cif_no"));
			String cert_code = ElementUtils.getXMLElementInStringValue(inMessage, String.format(xpathInput, "cert_code"));
			String cert_type = ElementUtils.getXMLElementInStringValue(inMessage, String.format(xpathInput, "cert_type"));
			CustomerInfo retCustomerInfo = null;
			CustomerInfoFacade custFacade = new CustomerInfoFacade();
			this.hostMessageLogInfo.setSend_time(AppUtils.now(Global.DEF_FORMAT_DATE_TIME_FULL));
			if (cif_no.length() > 0) {
				rebuildTransactionInfo(Global.SIBS_001, Global.APP_DEFAULT_BRANCH_CODE);
				retCustomerInfo = custFacade.getCustomerInfoByCIFOrID(cif_no, cert_code, cert_type);
			} else {
				if (cert_code.length() == 0) {
					this.retErrorInfo.setErrorCode(Global.ERR_UDF_CERT_CODE_NOT_VALID_OR_MISSING);
					this.retErrorInfo.setErrorMessage("ERR_UDF_CERT_CODE_NOT_VALID_OR_MISSING");
					return;
				}

				if (cert_type.length() == 0) {
					this.retErrorInfo.setErrorCode(Global.ERR_UDF_CERT_TYPE_NOT_VALID_OR_MISSING);
					this.retErrorInfo.setErrorMessage("ERR_UDF_CERT_TYPE_NOT_VALID_OR_MISSING");
					return;
				}
				rebuildTransactionInfo(Global.SIBS_002, Global.APP_DEFAULT_BRANCH_CODE);
				retCustomerInfo = custFacade.getCustomerInfoByCIFOrID(cif_no, cert_code, cert_type);
			}
			this.hostMessageLogInfo.setReceive_time(AppUtils.now(Global.DEF_FORMAT_DATE_TIME_FULL));

			if (retCustomerInfo != null) {
				hostResponseMessage = retCustomerInfo.toString();
				String xpathOutput = "/message/?body/?$field[set-value('%s')][?@name[set-value('%s')]]";
				ElementUtils.setXMLElementValue(outMessage, xpathOutput, retCustomerInfo.getCif_no(), "cif_no");
				ElementUtils.setXMLElementValue(outMessage, xpathOutput, retCustomerInfo.getCif_acct_name(), "cif_acct_name");
				ElementUtils.setXMLElementValue(outMessage, xpathOutput, retCustomerInfo.getStatus(), "status");
				ElementUtils.setXMLElementValue(outMessage, xpathOutput, retCustomerInfo.getBank_no(), "bank_no");
				ElementUtils.setXMLElementValue(outMessage, xpathOutput, retCustomerInfo.getCountry(), "country");
				ElementUtils.setXMLElementValue(outMessage, xpathOutput, retCustomerInfo.getGender(), "gender");
				ElementUtils.setXMLElementValue(outMessage, xpathOutput, retCustomerInfo.getCert_code(), "cert_code");
				ElementUtils.setXMLElementValue(outMessage, xpathOutput, retCustomerInfo.getCert_type(), "cert_type");
				ElementUtils.setXMLElementValue(outMessage, xpathOutput, retCustomerInfo.getBirth_date(), "birth_date");
				ElementUtils.setXMLElementValue(outMessage, xpathOutput, retCustomerInfo.getBirth_place(), "birth_place");
				ElementUtils.setXMLElementValue(outMessage, xpathOutput, retCustomerInfo.getIndividual(), "individual");
				ElementUtils.setXMLElementValue(outMessage, xpathOutput, retCustomerInfo.getTelephone(), "telephone");
				ElementUtils.setXMLElementValue(outMessage, xpathOutput, retCustomerInfo.getAddr(), "addr");
				ElementUtils.setXMLElementValue(outMessage, xpathOutput, retCustomerInfo.getMobile(), "mobile");
				ElementUtils.setXMLElementValue(outMessage, xpathOutput, retCustomerInfo.getEmail(), "email");
				ElementUtils.setXMLElementValue(outMessage, xpathOutput, retCustomerInfo.getContact_person(), "contact_person");
				ElementUtils.setXMLElementValue(outMessage, xpathOutput, CoreBankUtils.correctBranchCode(retCustomerInfo.getBranch_no()), "branch_no");
			} else {
				this.retErrorInfo.setErrorCode(Global.ERR_MBASE_START);
				this.retErrorInfo.setErrorMessage("No record found");

			}

			this.hostMessageLogInfo.setResp_code(String.valueOf(this.retErrorInfo.getErrorCode()));
			this.hostMessageLogInfo.setResp_msg(this.retErrorInfo.getErrorMessage());
			this.hostMessageLogInfo.setHostRequestMsg("[channel:" + hostMessageLogInfo.getRef_channel() + "," + "branch:" + hostMessageLogInfo.getBatch_no() + "," + "cif_no:"
					+ cif_no + ",cert_code:" + cert_code + "]");
			this.hostMessageLogInfo.setHostResponseMsg("[" + hostResponseMessage + "]");
			this.arrRetHOSTMessageLogInfo.add(hostMessageLogInfo);

		} catch (Exception ex) {
			ex.printStackTrace();
			logger.error(new StringBuffer().append("Error source:").append(CLASS_NAME + ".getCustomerInfo()\n").append("Error message:").append(ex.toString() + "\n"));
			this.retErrorInfo.setErrorCode(Global.ERR_SYSTEM_UNKNOWN_ERROR);
			this.retErrorInfo.setErrorMessage(ex.toString());
		}
	}

	private void getCustomerInfoOnline() {
		try {
			String xpathInput = "/message/body/field[@name='%s']";
			String cif_no = ElementUtils.getXMLElementInStringValue(inMessage, String.format(xpathInput, "cif_no"));
			String cert_code = ElementUtils.getXMLElementInStringValue(inMessage, String.format(xpathInput, "cert_code"));
			String cert_type = ElementUtils.getXMLElementInStringValue(inMessage, String.format(xpathInput, "cert_type"));

			this.hostMessageLogInfo.setSend_time(AppUtils.now(Global.DEF_FORMAT_DATE_TIME_FULL));
			try {
				if (cif_no.length() > 0) {
					rebuildTransactionInfo(Global.SIBS_001, Global.APP_DEFAULT_BRANCH_CODE);
					retMessage = as400Port.getInformationByCIFForIBSRegistration(hostMessageLogInfo.getRef_channel(), hostMessageLogInfo.getTeller_id(), hostMessageLogInfo
							.getWs_ip(), hostMessageLogInfo.getBranch_code(), cif_no);

				} else {
					if (cert_code.length() == 0) {
						this.retErrorInfo.setErrorCode(Global.ERR_UDF_CERT_CODE_NOT_VALID_OR_MISSING);
						this.retErrorInfo.setErrorMessage("ERR_UDF_CERT_CODE_NOT_VALID_OR_MISSING");
						return;
					}

					if (cert_type.length() == 0) {
						this.retErrorInfo.setErrorCode(Global.ERR_UDF_CERT_TYPE_NOT_VALID_OR_MISSING);
						this.retErrorInfo.setErrorMessage("ERR_UDF_CERT_TYPE_NOT_VALID_OR_MISSING");
						return;
					}
					rebuildTransactionInfo(Global.SIBS_002, Global.APP_DEFAULT_BRANCH_CODE);
					retMessage = as400Port.getInformationByIDForIBSRegistration(hostMessageLogInfo.getRef_channel(), hostMessageLogInfo.getTeller_id(), hostMessageLogInfo
							.getWs_ip(), hostMessageLogInfo.getBranch_code(), cert_code);
				}
			} catch (RemoteException e) {
				retErrorInfo.setErrorCode(ERR_CM_EXCEPTION_WHEN_CALL_ONECONNECT);
				retErrorInfo.setErrorMessage(e.getMessage());
			}
			// Log response time
			this.hostMessageLogInfo.setReceive_time(AppUtils.now(Global.DEF_FORMAT_DATE_TIME_FULL));
			if (retMessage != null) {
				if (retMessage.getErrCode() == null) {
					hostResponseMessage = AppUtils.convertArrayToString(retMessage.getArrString());
					if (retMessage.getArrString() != null & retMessage.getArrString().length > 0) {
						String xpathOutput = "/message/?body/?$field[set-value('%s')][?@name[set-value('%s')]]";
						ElementUtils.setXMLElementValue(outMessage, xpathOutput, retMessage.getArrString()[0], "cif_no");
						ElementUtils.setXMLElementValue(outMessage, xpathOutput, retMessage.getArrString()[1], "cif_acct_name");
						ElementUtils.setXMLElementValue(outMessage, xpathOutput, retMessage.getArrString()[2], "status");
						ElementUtils.setXMLElementValue(outMessage, xpathOutput, retMessage.getArrString()[3], "bank_no");
						ElementUtils.setXMLElementValue(outMessage, xpathOutput, retMessage.getArrString()[4], "country");
						ElementUtils.setXMLElementValue(outMessage, xpathOutput, retMessage.getArrString()[5], "gender");
						ElementUtils.setXMLElementValue(outMessage, xpathOutput, retMessage.getArrString()[6], "cert_code");
						ElementUtils.setXMLElementValue(outMessage, xpathOutput, retMessage.getArrString()[7], "cert_type");
						ElementUtils.setXMLElementValue(outMessage, xpathOutput, CoreBankUtils.convertCB2EBDate(retMessage.getArrString()[8]), "birth_date");
						ElementUtils.setXMLElementValue(outMessage, xpathOutput, retMessage.getArrString()[9], "birth_place");
						ElementUtils.setXMLElementValue(outMessage, xpathOutput, retMessage.getArrString()[10], "individual");
						ElementUtils.setXMLElementValue(outMessage, xpathOutput, retMessage.getArrString()[11], "telephone");
						ElementUtils.setXMLElementValue(outMessage, xpathOutput, retMessage.getArrString()[12] + "," + retMessage.getArrString()[13] + ","
								+ retMessage.getArrString()[14], "addr");
						ElementUtils.setXMLElementValue(outMessage, xpathOutput, retMessage.getArrString()[15], "mobile");
						ElementUtils.setXMLElementValue(outMessage, xpathOutput, retMessage.getArrString()[16], "email");
						ElementUtils.setXMLElementValue(outMessage, xpathOutput, retMessage.getArrString()[17], "contact_person");
						ElementUtils.setXMLElementValue(outMessage, xpathOutput, CoreBankUtils.correctBranchCode(retMessage.getArrString()[18]), "branch_no");
					}
				} else {
					this.retErrorInfo.setErrorCode(Global.ERR_MBASE_START);
					this.retErrorInfo.setErrorMessage(retMessage.getDescription());
				}
			}

			this.hostMessageLogInfo.setResp_code(String.valueOf(this.retErrorInfo.getErrorCode()));
			this.hostMessageLogInfo.setResp_msg(this.retErrorInfo.getErrorMessage());
			this.hostMessageLogInfo.setHostRequestMsg("[channel:" + hostMessageLogInfo.getRef_channel() + "," + "branch:" + hostMessageLogInfo.getBatch_no() + "," + "cif_no:"
					+ cif_no + ",cert_code:" + cert_code + "]");
			this.hostMessageLogInfo.setHostResponseMsg("[" + hostResponseMessage + "]");
			this.arrRetHOSTMessageLogInfo.add(hostMessageLogInfo);

		} catch (Exception ex) {
			ex.printStackTrace();
			logger.error(new StringBuffer().append("Error source:").append(CLASS_NAME + ".getCustomerInfo()\n").append("Error message:").append(ex.toString() + "\n"));
			this.retErrorInfo.setErrorCode(Global.ERR_SYSTEM_UNKNOWN_ERROR);
			this.retErrorInfo.setErrorMessage(ex.toString());
		}
	}

	/**
	 * 
	 */
	private void getCustomerAccounts() {
		try {
			String xpathInput = "/message/body/field[@name='%s']";
			String cif_no = ElementUtils.getXMLElementInStringValue(inMessage, String.format(xpathInput, "cif_no"));
			String acct_type = ElementUtils.getXMLElementInStringValue(inMessage, String.format(xpathInput, "acct_type"));
			String acct_no = ElementUtils.getXMLElementInStringValue(inMessage, String.format(xpathInput, "acct_no"));
			String acct_ccy = ElementUtils.getXMLElementInStringValue(inMessage, String.format(xpathInput, "acct_ccy"));

			if (cif_no.length() > 0) {
				getListOfCustomerAccountOffline(cif_no);
				// getListOfCustomerAccount(cif_no);
			} else {
				getAccountInfoOffline(acct_no, acct_type, acct_ccy);
				// getAccountInfoOnline(acct_no, acct_type, acct_ccy);
			}

		} catch (Exception ex) {
			ex.printStackTrace();
			logger.error(new StringBuffer().append("Error source:").append(CLASS_NAME + ".getCustomerAccount()\n").append("Error message:").append(ex.toString() + "\n"));
			this.retErrorInfo.setErrorCode(Global.ERR_SYSTEM_UNKNOWN_ERROR);
			this.retErrorInfo.setErrorMessage(ex.getMessage());
		}
	}

	/**
	 * Get customer account info
	 * 
	 * @param acct_no
	 * @param acct_type
	 * @param acct_ccy
	 */
	private void getAccountInfoOffline(String acct_no, String acct_type, String acct_ccy) {
		try {
			AccountInfo tempAccount = new AccountInfo();
			AccountInfoFacade acctFacade = new AccountInfoFacade();
			this.hostMessageLogInfo.setSend_time(AppUtils.now(Global.DEF_FORMAT_DATE_TIME_FULL));
			try {
				if (acct_type.equals(Global.COREBBANK_CA_ACCOUNT_TYPE)) {
					rebuildTransactionInfo(Global.SIBS_003, Global.APP_DEFAULT_BRANCH_CODE);
				} else if (acct_type.equals(Global.COREBBANK_SA_ACCOUNT_TYPE)) {
					rebuildTransactionInfo(Global.SIBS_004, Global.APP_DEFAULT_BRANCH_CODE);
				} else if (acct_type.equals(Global.COREBBANK_FD_RECEIPT_ACCOUNT_TYPE)) {
					rebuildTransactionInfo(Global.SIBS_005, Global.APP_DEFAULT_BRANCH_CODE);
				} else if (acct_type.equals(Global.COREBBANK_FD_GROUP_ACCOUNT_TYPE)) {
					rebuildTransactionInfo(Global.SIBS_006, Global.APP_DEFAULT_BRANCH_CODE);
				} else if (acct_type.equals(Global.COREBBANK_LN_ACCOUNT_TYPE)) {
					rebuildTransactionInfo(Global.SIBS_007, Global.APP_DEFAULT_BRANCH_CODE);
				}

				tempAccount = acctFacade.getAccountInfoByAccountNo(acct_no, acct_type);
			} catch (Exception ex) {
			}
			this.hostMessageLogInfo.setReceive_time(AppUtils.now(Global.DEF_FORMAT_DATE_TIME_FULL));
			if (tempAccount == null) {
				this.retErrorInfo.setErrorCode(Global.ERR_MBASE_START);
				this.retErrorInfo.setErrorMessage("No record found");
			}

			if (retErrorInfo.getErrorCode() == ERR_SYSTEM_OK) {
				// 1.Tao node list,entity
				String xpathOutput = "/message/?body/?list[?@name[set-value('records')]]/?entity[?@name[set-value('0')]]";// /?$field[set-value('%s')][?@name[set-value('%s')]]";
				ElementUtils.setXMLElementValue(outMessage, xpathOutput);
				// 2.Tao cac field
				xpathOutput = "/message/body/list[@name[set-value('records')]]/entity[@name[set-value('0')]]/?$field[set-value('%s')][?@name[set-value('%s')]]";
				ElementUtils.setXMLElementValue(outMessage, xpathOutput, tempAccount.getCif_no(), "cif_no");
				ElementUtils.setXMLElementValue(outMessage, xpathOutput, CoreBankUtils.correctAccountNumber(acct_no), "acct_no");
				ElementUtils.setXMLElementValue(outMessage, xpathOutput, tempAccount.getAcct_ccy(), "acct_ccy");
				ElementUtils.setXMLElementValue(outMessage, xpathOutput, tempAccount.getAcct_type(), "acct_type");
				ElementUtils.setXMLElementValue(outMessage, xpathOutput, tempAccount.getSub_acct_type(), "sub_acct_type");
				ElementUtils.setXMLElementValue(outMessage, xpathOutput, AppUtils.XMLReplaceSpecChar(tempAccount.getAcct_name()), "acct_name");
				ElementUtils.setXMLElementValue(outMessage, xpathOutput, CoreBankUtils.correctAccountNumber(tempAccount.getP_acct_no()), "p_acct_no");
				ElementUtils.setXMLElementValue(outMessage, xpathOutput, CoreBankUtils.correctBranchCode(tempAccount.getBranch_no()), "branch_no");
				ElementUtils.setXMLElementValue(outMessage, xpathOutput, tempAccount.getSub_branch_no(), "sub_branch_no");
				ElementUtils.setXMLElementValue(outMessage, xpathOutput, tempAccount.getCb_sign(), "cb_sign");
				ElementUtils.setXMLElementValue(outMessage, xpathOutput, tempAccount.getCert_type(), "cert_type");
				ElementUtils.setXMLElementValue(outMessage, xpathOutput, tempAccount.getCert_code(), "cert_code");
				ElementUtils.setXMLElementValue(outMessage, xpathOutput, tempAccount.getCx_sign(), "cx_sign");
				ElementUtils.setXMLElementValue(outMessage, xpathOutput, CoreBankUtils.convertCB2EBDate(tempAccount.getEstablish_date()), "establish_date");
				ElementUtils.setXMLElementValue(outMessage, xpathOutput, CoreBankUtils.convertCB2EBDate(tempAccount.getAvailable_date()), "available_date");
				ElementUtils.setXMLElementValue(outMessage, xpathOutput, tempAccount.getRemark(), "remark");
				ElementUtils.setXMLElementValue(outMessage, xpathOutput, tempAccount.getCurrent_balance(), "current_balance");
				ElementUtils.setXMLElementValue(outMessage, xpathOutput, tempAccount.getFreezed_balance(), "freezed_balance");
				ElementUtils.setXMLElementValue(outMessage, xpathOutput, tempAccount.getAvailable_balance(), "available_balance");
				ElementUtils.setXMLElementValue(outMessage, xpathOutput, tempAccount.getCreate_by(), "create_by");
				ElementUtils.setXMLElementValue(outMessage, xpathOutput, tempAccount.getCreate_time(), "create_time");
				ElementUtils.setXMLElementValue(outMessage, xpathOutput, tempAccount.getUpdate_by(), "update_by");
				ElementUtils.setXMLElementValue(outMessage, xpathOutput, tempAccount.getUpdate_time(), "update_time");
				ElementUtils.setXMLElementValue(outMessage, xpathOutput, tempAccount.getLedger_balance(), "ledger_balance");
				ElementUtils.setXMLElementValue(outMessage, xpathOutput, tempAccount.getHold_amt(), "hold_amt");
				ElementUtils.setXMLElementValue(outMessage, xpathOutput, tempAccount.getOverdraft_limit(), "overdraft_limit");
				ElementUtils.setXMLElementValue(outMessage, xpathOutput, tempAccount.getInterest_rate(), "interest_rate");
				ElementUtils.setXMLElementValue(outMessage, xpathOutput, CoreBankUtils.convertCB2EBDate(tempAccount.getDate_acct_opened()), "date_acct_opened");
				ElementUtils.setXMLElementValue(outMessage, xpathOutput, tempAccount.getPassbook_no(), "passbook_no");
				ElementUtils.setXMLElementValue(outMessage, xpathOutput, tempAccount.getAccured_interest(), "accured_interest");
				ElementUtils.setXMLElementValue(outMessage, xpathOutput, tempAccount.getTerm(), "term");
				ElementUtils.setXMLElementValue(outMessage, xpathOutput, tempAccount.getOri_balance(), "ori_balance");
				ElementUtils.setXMLElementValue(outMessage, xpathOutput, tempAccount.getPrincipal_balance(), "principal_balance");
				ElementUtils.setXMLElementValue(outMessage, xpathOutput, tempAccount.getPenalty_amt(), "penalty_amt");
				ElementUtils.setXMLElementValue(outMessage, xpathOutput, tempAccount.getCurrent_cash_value(), "current_cash_value");
				ElementUtils.setXMLElementValue(outMessage, xpathOutput, tempAccount.getEarmarked_amt(), "earmarked_amt");
				ElementUtils.setXMLElementValue(outMessage, xpathOutput, CoreBankUtils.convertCB2EBDate(tempAccount.getIssued_date()), "issued_date");
				ElementUtils.setXMLElementValue(outMessage, xpathOutput, CoreBankUtils.convertCB2EBDate(tempAccount.getMaturity_date()), "maturity_date");
				ElementUtils.setXMLElementValue(outMessage, xpathOutput, tempAccount.getTimes_nenewed_count(), "times_nenewed_count");
				ElementUtils.setXMLElementValue(outMessage, xpathOutput, tempAccount.getPurpose_code(), "purpose_code");
				ElementUtils.setXMLElementValue(outMessage, xpathOutput, tempAccount.getLoan_ori_amt(), "loan_ori_amt");
				ElementUtils.setXMLElementValue(outMessage, xpathOutput, tempAccount.getOs_balance(), "os_balance");
				ElementUtils.setXMLElementValue(outMessage, xpathOutput, tempAccount.getOs_principal(), "os_principal");
				ElementUtils.setXMLElementValue(outMessage, xpathOutput, tempAccount.getLoan_term(), "loan_term");
				ElementUtils.setXMLElementValue(outMessage, xpathOutput, tempAccount.getPrincipal_frequent(), "principal_frequent");
				ElementUtils.setXMLElementValue(outMessage, xpathOutput, tempAccount.getInterest_frequent(), "interest_frequent");
				ElementUtils.setXMLElementValue(outMessage, xpathOutput, tempAccount.getFull_release_date(), "full_release_date");
				ElementUtils.setXMLElementValue(outMessage, xpathOutput, tempAccount.getOverdue_indicator_desc(), "overdue_indicator_desc");
				ElementUtils.setXMLElementValue(outMessage, xpathOutput, tempAccount.getAcct_status(), "acct_status");
				ElementUtils.setXMLElementValue(outMessage, xpathOutput, tempAccount.getLoan_term_code(), "loan_term_code");
				// ElementUtils.setXMLElementValue(outMessage, xpathOutput,
				// tempAccount.getBilled_total_amt(), "billed_total_amt");
				ElementUtils.setXMLElementValue(outMessage, xpathOutput, tempAccount.getBilled_late_charge(), "billed_late_charge");
				ElementUtils.setXMLElementValue(outMessage, xpathOutput, tempAccount.getBilled_principal(), "billed_principal");
				ElementUtils.setXMLElementValue(outMessage, xpathOutput, tempAccount.getBilled_interest(), "billed_interest");
				ElementUtils.setXMLElementValue(outMessage, xpathOutput, tempAccount.getPayment_amt(), "payment_amt");
				ElementUtils.setXMLElementValue(outMessage, xpathOutput, tempAccount.getFinal_payment_amt(), "final_payment_amt");
			}
			this.hostMessageLogInfo.setResp_code(String.valueOf(retErrorInfo.getErrorCode()));
			this.hostMessageLogInfo.setResp_msg(retErrorInfo.getErrorMessage());
			this.hostMessageLogInfo.setHostRequestMsg("[" + hostRequestMessage + "]");
			this.hostMessageLogInfo.setHostResponseMsg("[" + hostResponseMessage + "]");
			this.arrRetHOSTMessageLogInfo.add(hostMessageLogInfo);
		} catch (Exception ex) {
			ex.printStackTrace();
			logger.error(new StringBuffer().append("Error source:").append(CLASS_NAME + ".getAccount()\n").append("Error message:").append(ex.toString() + "\n"));
			this.retErrorInfo.setErrorCode(Global.ERR_SYSTEM_UNKNOWN_ERROR);
			this.retErrorInfo.setErrorMessage(ex.toString());
		}
	}

	/**
	 * 
	 * @param acct_no
	 * @param acct_type
	 * @param acct_ccy
	 */
	private void getAccountInfoOnline(String acct_no, String acct_type, String acct_ccy) {
		try {

			String cif_no = "", sub_acct_type = "", acct_name = "", p_acct_no = "", sub_branch_no = "";
			String cb_sign = "", cx_sign = "", establish_date = "", available_date = "";
			String branch_no = "", cert_type = "", cert_code = "", remark = "";
			String current_balance = "", freezed_balance = "", available_balance = "", create_by = "";
			String create_time = "", update_by = "", update_time = "", ledger_balance = "";
			String hold_amt = "", overdraft_limit = "", interest_rate = "";
			String date_acct_opened = "", passbook_no = "", accured_interest = "", term = "";
			String ori_balance = "", principal_balance = "", penalty_amt = "", current_cash_value = "";
			String earmarked_amt = "", issued_date = "", maturity_date = "";
			String times_nenewed_count = "", purpose_code = "", loan_ori_amt = "", os_balance = "";
			String loan_term = "", principal_frequent = "", interest_frequent = "", full_release_date = "";
			String overdue_indicator_desc = "", loan_term_code = "", acct_status = "", product_code = "";
			String billed_late_charge = "", billed_principal = "", billed_interest = "", payment_amt = "", final_payment_amt = "";
			String os_principal = "", accured_interest_due = "", billed_other_charge = "", billed_misc_charge = "";
			String billed_total_amt = "";

			MBASE_TEMPLATE[2] = hostMessageLogInfo.getWs_ip();
			MBASE_TEMPLATE[25] = hostMessageLogInfo.getTeller_id();
			MBASE_TEMPLATE[26] = hostMessageLogInfo.getWs_name();
			MBASE_TEMPLATE[32] = hostMessageLogInfo.getApprover_id();
			MBASE_TEMPLATE[40] = hostMessageLogInfo.getWs_name();
			MBASE_TEMPLATE[42] = hostMessageLogInfo.getBranch_code();
			// Kienvt : cho phep inquiry nhieu hon

			int startPos = 0, recordLength = 0;

			if (acct_no.length() > 0) {
				if (acct_type.equals(Global.COREBBANK_CA_ACCOUNT_TYPE)) {
					startPos = 67;
					recordLength = 120;
					rebuildTransactionInfo(Global.SIBS_003, Global.APP_DEFAULT_BRANCH_CODE);
					MBASE_TEMPLATE[18] = "BBMBSDDINQFNC";// scenarioNumber
					MBASE_TEMPLATE[27] = this.hostMessageLogInfo.getHost_tran_code();// "26161";
					MBASE_TEMPLATE[46] = this.hostMessageLogInfo.getHost_tran_code();// "26161";
					MBASE_TEMPLATE[68] = acct_no;
					MBASE_TEMPLATE[69] = acct_type;
				} else if (acct_type.equals(Global.COREBBANK_SA_ACCOUNT_TYPE)) {
					startPos = 67;
					recordLength = 120;
					rebuildTransactionInfo(Global.SIBS_004, Global.APP_DEFAULT_BRANCH_CODE);
					MBASE_TEMPLATE[18] = "BBMBSDDINQFNC";// scenarioNumber
					MBASE_TEMPLATE[27] = this.hostMessageLogInfo.getHost_tran_code();// "26161";
					MBASE_TEMPLATE[46] = this.hostMessageLogInfo.getHost_tran_code();// "26161";
					MBASE_TEMPLATE[68] = acct_no;
					MBASE_TEMPLATE[69] = acct_type;
				} else if (acct_type.equals(Global.COREBBANK_FD_RECEIPT_ACCOUNT_TYPE)) {
					startPos = 67;
					recordLength = 50;
					rebuildTransactionInfo(Global.SIBS_005, Global.APP_DEFAULT_BRANCH_CODE);
					MBASE_TEMPLATE[18] = "BBMBSCDINQFNC";// scenarioNumber
					MBASE_TEMPLATE[27] = this.hostMessageLogInfo.getHost_tran_code();// "36501";
					MBASE_TEMPLATE[46] = this.hostMessageLogInfo.getHost_tran_code();// "36501";
					MBASE_TEMPLATE[64] = acct_no;
					MBASE_TEMPLATE[68] = acct_no;
					MBASE_TEMPLATE[65] = acct_type;
					MBASE_TEMPLATE[69] = acct_type;
				} else if (acct_type.equals(Global.COREBBANK_FD_GROUP_ACCOUNT_TYPE)) {
					startPos = 67;
					recordLength = 50;
					rebuildTransactionInfo(Global.SIBS_006, Global.APP_DEFAULT_BRANCH_CODE);
					MBASE_TEMPLATE[18] = "BBMBSCDINQFNC";// scenarioNumber
					MBASE_TEMPLATE[27] = this.hostMessageLogInfo.getHost_tran_code();// "36501";
					MBASE_TEMPLATE[46] = this.hostMessageLogInfo.getHost_tran_code();// "36501";
					MBASE_TEMPLATE[64] = acct_no;
					MBASE_TEMPLATE[68] = acct_no;
					MBASE_TEMPLATE[65] = acct_type;
					MBASE_TEMPLATE[69] = acct_type;
				} else if (acct_type.equals(Global.COREBBANK_LN_ACCOUNT_TYPE)) {
					startPos = 67;
					recordLength = 53;
					rebuildTransactionInfo(Global.SIBS_007, Global.APP_DEFAULT_BRANCH_CODE);
					MBASE_TEMPLATE[18] = "BBMBSLNINQFNC";// scenarioNumber
					MBASE_TEMPLATE[27] = this.hostMessageLogInfo.getHost_tran_code();// "86820";
					MBASE_TEMPLATE[46] = this.hostMessageLogInfo.getHost_tran_code();// "86820";
					MBASE_TEMPLATE[68] = acct_no;
					MBASE_TEMPLATE[69] = acct_type;
				}
			}
			hostRequestMessage = AppUtils.convertArrayToString(MBASE_TEMPLATE);
			this.hostMessageLogInfo.setSend_time(AppUtils.now(Global.DEF_FORMAT_DATE_TIME_FULL));
			try {
				retMessage = as400Port.hostMessageSending(hostMessageLogInfo.getRef_channel(), hostRequestMessage);
			} catch (RemoteException ex) {
				this.retErrorInfo.setErrorCode(Global.ERR_CM_EXCEPTION_WHEN_CALL_ONECONNECT);
				this.retErrorInfo.setErrorMessage(ex.toString());
			}
			this.hostMessageLogInfo.setReceive_time(AppUtils.now(Global.DEF_FORMAT_DATE_TIME_FULL));
			hostResponseMessage = AppUtils.convertArrayToString(retMessage.getArrString());
			ArrayList<String[]> retArrOfResult = null;
			if (retMessage != null) {
				if (retMessage.getErrCode() == null) {
					retArrOfResult = AppUtils.getListOfResponseRow(retMessage.getArrString(), startPos, recordLength);
				} else {
					this.retErrorInfo.setErrorCode(Global.ERR_MBASE_START);
					this.retErrorInfo.setErrorMessage(retMessage.getDescription());
				}
			} else {
				this.retErrorInfo.setErrorCode(Global.ERR_CM_EXCEPTION_WHEN_CALL_ONECONNECT);
				this.retErrorInfo.setErrorMessage("ERR_CM_EXCEPTION_WHEN_CALL_ONECONNECT");
			}

			if (retArrOfResult != null && retArrOfResult.size() > 0) {
				// Gan lai gia tri
				if (acct_type.equals(Global.COREBBANK_CA_ACCOUNT_TYPE)) {
					acct_no = (String) retArrOfResult.get(0)[0];
					acct_type = (String) retArrOfResult.get(0)[1];
					acct_name = (String) retArrOfResult.get(0)[2];
					cif_no = (String) retArrOfResult.get(0)[8];
					branch_no = (String) retArrOfResult.get(0)[9];
					acct_ccy = (String) retArrOfResult.get(0)[10];
					cert_code = (String) retArrOfResult.get(0)[117];
					cert_type = (String) retArrOfResult.get(0)[118];
					available_balance = (String) retArrOfResult.get(0)[16];
					hold_amt = (String) retArrOfResult.get(0)[20];
					overdraft_limit = (String) retArrOfResult.get(0)[18];
					hold_amt = (String) retArrOfResult.get(0)[18];
					interest_rate = (String) retArrOfResult.get(0)[47];
					acct_status = (String) retArrOfResult.get(0)[54];
					date_acct_opened = CoreBankUtils.convertCB2EBDate((String) retArrOfResult.get(0)[12]);// yyyyMMdd
					ledger_balance = (String) retArrOfResult.get(0)[17];
					accured_interest = (String) retArrOfResult.get(0)[62];
				} else if (acct_type.equals(Global.COREBBANK_SA_ACCOUNT_TYPE)) {
					acct_no = (String) retArrOfResult.get(0)[0];
					acct_type = (String) retArrOfResult.get(0)[1];
					acct_name = (String) retArrOfResult.get(0)[2];
					cif_no = (String) retArrOfResult.get(0)[8];
					branch_no = (String) retArrOfResult.get(0)[9];
					acct_ccy = (String) retArrOfResult.get(0)[10];
					cert_code = (String) retArrOfResult.get(0)[117];
					cert_type = (String) retArrOfResult.get(0)[118];
					passbook_no = (String) retArrOfResult.get(0)[16];
					available_balance = (String) retArrOfResult.get(0)[16];
					hold_amt = (String) retArrOfResult.get(0)[20];
					earmarked_amt = (String) retArrOfResult.get(0)[18];
					ledger_balance = (String) retArrOfResult.get(0)[17];
					interest_rate = (String) retArrOfResult.get(0)[47];
					acct_status = (String) retArrOfResult.get(0)[54];
					date_acct_opened = CoreBankUtils.convertCB2EBDate((String) retArrOfResult.get(0)[12]);// yyyyMMdd
				} else if (acct_type.equals(Global.COREBBANK_FD_RECEIPT_ACCOUNT_TYPE) || acct_type.equals(Global.COREBBANK_FD_GROUP_ACCOUNT_TYPE)) {
					acct_no = (String) retArrOfResult.get(0)[0];
					passbook_no = (String) retArrOfResult.get(0)[10];
					acct_type = (String) retArrOfResult.get(0)[1];
					acct_name = (String) retArrOfResult.get(0)[2];
					p_acct_no = (String) retArrOfResult.get(0)[6];
					cif_no = (String) retArrOfResult.get(0)[3];
					branch_no = (String) retArrOfResult.get(0)[5];
					// acct_ccy = (String) retArrOfResult.get(0)[10];
					ori_balance = (String) retArrOfResult.get(0)[14];
					principal_balance = (String) retArrOfResult.get(0)[19];
					accured_interest = (String) retArrOfResult.get(0)[21];
					penalty_amt = (String) retArrOfResult.get(0)[23];
					acct_status = (String) retArrOfResult.get(0)[13];
					maturity_date = CoreBankUtils.convertCB2EBDate((String) retArrOfResult.get(0)[24]);
					current_cash_value = (String) retArrOfResult.get(0)[30];
					interest_rate = (String) retArrOfResult.get(0)[33];
					interest_frequent = (String) retArrOfResult.get(0)[15];
					term = (String) retArrOfResult.get(0)[16];
					establish_date = CoreBankUtils.convertCB2EBDate((String) retArrOfResult.get(0)[20]);
					product_code = (String) retArrOfResult.get(0)[49];
				} else if (acct_type.equals(Global.COREBBANK_LN_ACCOUNT_TYPE)) {
					acct_no = (String) retArrOfResult.get(0)[0];
					acct_type = (String) retArrOfResult.get(0)[1];
					acct_name = (String) retArrOfResult.get(0)[10];
					p_acct_no = (String) retArrOfResult.get(0)[6];
					cif_no = (String) retArrOfResult.get(0)[2];
					branch_no = (String) retArrOfResult.get(0)[3];
					acct_ccy = (String) retArrOfResult.get(0)[5];
					loan_ori_amt = (String) retArrOfResult.get(0)[17];
					os_balance = (String) retArrOfResult.get(0)[34];
					os_principal = (String) retArrOfResult.get(0)[16];
					accured_interest_due = (String) retArrOfResult.get(0)[18];
					available_balance = (String) retArrOfResult.get(0)[37];
					earmarked_amt = (String) retArrOfResult.get(0)[38];
					final_payment_amt = (String) retArrOfResult.get(0)[33];
				}
			}

			// Tai khoan Loan
			if (acct_type.equals(Global.COREBBANK_LN_ACCOUNT_TYPE)) {
				startPos = 67;
				recordLength = 62;
				rebuildTransactionInfo(SIBS_008, Global.APP_DEFAULT_BRANCH_CODE);
				MBASE_TEMPLATE[18] = "BBMBSLNINQFNC";// scenarioNumber
				MBASE_TEMPLATE[27] = hostMessageLogInfo.getHost_tran_code(); // "86821";
				MBASE_TEMPLATE[46] = hostMessageLogInfo.getHost_tran_code();// "86821";
				MBASE_TEMPLATE[68] = acct_no;
				MBASE_TEMPLATE[69] = acct_type;

				hostRequestMessage = AppUtils.convertArrayToString(MBASE_TEMPLATE);
				this.hostMessageLogInfo.setSend_time(AppUtils.now(Global.DEF_FORMAT_DATE_TIME_FULL));
				try {
					retMessage = as400Port.hostMessageSending(hostMessageLogInfo.getRef_channel(), hostRequestMessage);
				} catch (RemoteException ex) {
					this.retErrorInfo.setErrorCode(Global.ERR_CM_EXCEPTION_WHEN_CALL_ONECONNECT);
					this.retErrorInfo.setErrorMessage(ex.toString());
				}
				this.hostMessageLogInfo.setReceive_time(AppUtils.now(Global.DEF_FORMAT_DATE_TIME_FULL));
				hostResponseMessage = AppUtils.convertArrayToString(retMessage.getArrString());
				if (retMessage != null) {
					if (retMessage.getErrCode() == null) {
						retArrOfResult = AppUtils.getListOfResponseRow(retMessage.getArrString(), startPos, recordLength);
						if (retArrOfResult.size() > 0) {
							acct_no = (String) retArrOfResult.get(0)[0];
							acct_type = (String) retArrOfResult.get(0)[1];
							acct_name = (String) retArrOfResult.get(0)[10];
							cif_no = (String) retArrOfResult.get(0)[2];
							branch_no = (String) retArrOfResult.get(0)[3];
							acct_ccy = (String) retArrOfResult.get(0)[5];
							loan_term = (String) retArrOfResult.get(0)[16];
							loan_term_code = (String) retArrOfResult.get(0)[17];
							billed_principal = (String) retArrOfResult.get(0)[48];
							billed_interest = (String) retArrOfResult.get(0)[49];
							billed_late_charge = (String) retArrOfResult.get(0)[51];
							billed_other_charge = (String) retArrOfResult.get(0)[52];
							billed_misc_charge = (String) retArrOfResult.get(0)[53];
						}
					} else {
						this.retErrorInfo.setErrorCode(Global.ERR_MBASE_START);
						this.retErrorInfo.setErrorMessage(retMessage.getDescription());
					}
				}
				this.hostMessageLogInfo.setResp_code(String.valueOf(retErrorInfo.getErrorCode()));
				this.hostMessageLogInfo.setResp_msg(retErrorInfo.getErrorMessage());
				this.hostMessageLogInfo.setHostRequestMsg("[" + hostRequestMessage + "]");
				this.hostMessageLogInfo.setHostResponseMsg("[" + hostResponseMessage + "]");
				this.arrRetHOSTMessageLogInfo.add((HOSTMessagLogInfo) hostMessageLogInfo.clone());

				// Lay trang thai tai khoan LOAN
				startPos = 67;
				recordLength = 62;
				this.refTranCode = SIBS_008;

				MBASE_TEMPLATE[18] = "BBMBSLNINQFNC";// scenarioNumber
				MBASE_TEMPLATE[27] = "85800";
				MBASE_TEMPLATE[46] = "85800";
				MBASE_TEMPLATE[68] = acct_no;
				MBASE_TEMPLATE[69] = acct_type;

				hostRequestMessage = AppUtils.convertArrayToString(MBASE_TEMPLATE);
				this.hostMessageLogInfo.setSend_time(AppUtils.now(Global.DEF_FORMAT_DATE_TIME_FULL));
				try {
					retMessage = as400Port.hostMessageSending(hostMessageLogInfo.getRef_channel(), hostRequestMessage);
				} catch (RemoteException ex) {
					this.retErrorInfo.setErrorCode(Global.ERR_CM_EXCEPTION_WHEN_CALL_ONECONNECT);
					this.retErrorInfo.setErrorMessage(ex.toString());
				}
				this.hostMessageLogInfo.setReceive_time(AppUtils.now(Global.DEF_FORMAT_DATE_TIME_FULL));
				hostResponseMessage = AppUtils.convertArrayToString(retMessage.getArrString());
				if (retMessage != null) {
					if (retMessage.getErrCode() == null) {
						retArrOfResult = AppUtils.getListOfResponseRow(retMessage.getArrString(), startPos, recordLength);
						if (retArrOfResult.size() > 0) {
							acct_status = (String) retArrOfResult.get(0)[13];
						}
					} else {
						this.retErrorInfo.setErrorCode(Global.ERR_MBASE_START);
						this.retErrorInfo.setErrorMessage(retMessage.getDescription());
					}
				}
				this.hostMessageLogInfo.setResp_code(String.valueOf(retErrorInfo.getErrorCode()));
				this.hostMessageLogInfo.setResp_msg(retErrorInfo.getErrorMessage());
				this.hostMessageLogInfo.setHostRequestMsg("[" + hostRequestMessage + "]");
				this.hostMessageLogInfo.setHostResponseMsg("[" + hostResponseMessage + "]");
				this.arrRetHOSTMessageLogInfo.add((HOSTMessagLogInfo) hostMessageLogInfo.clone());
			}

			if (retErrorInfo.getErrorCode() == ERR_SYSTEM_OK) {
				// 1.Tao node list,entity
				String xpathOutput = "/message/?body/?list[?@name[set-value('records')]]/?entity[?@name[set-value('0')]]";// /?$field[set-value('%s')][?@name[set-value('%s')]]";
				ElementUtils.setXMLElementValue(outMessage, xpathOutput);
				// 2.Tao cac field
				xpathOutput = "/message/body/list[@name[set-value('records')]]/entity[@name[set-value('0')]]/?$field[set-value('%s')][?@name[set-value('%s')]]";
				ElementUtils.setXMLElementValue(outMessage, xpathOutput, cif_no, "cif_no");
				ElementUtils.setXMLElementValue(outMessage, xpathOutput, CoreBankUtils.correctAccountNumber(acct_no), "acct_no");
				ElementUtils.setXMLElementValue(outMessage, xpathOutput, acct_ccy, "acct_ccy");
				ElementUtils.setXMLElementValue(outMessage, xpathOutput, acct_type, "acct_type");
				ElementUtils.setXMLElementValue(outMessage, xpathOutput, sub_acct_type, "sub_acct_type");
				ElementUtils.setXMLElementValue(outMessage, xpathOutput, acct_name, "acct_name");
				ElementUtils.setXMLElementValue(outMessage, xpathOutput, p_acct_no, "p_acct_no");
				ElementUtils.setXMLElementValue(outMessage, xpathOutput, CoreBankUtils.correctBranchCode(branch_no), "branch_no");
				ElementUtils.setXMLElementValue(outMessage, xpathOutput, sub_branch_no, "sub_branch_no");
				ElementUtils.setXMLElementValue(outMessage, xpathOutput, cb_sign, "cb_sign");
				ElementUtils.setXMLElementValue(outMessage, xpathOutput, cert_type, "cert_type");
				ElementUtils.setXMLElementValue(outMessage, xpathOutput, cert_code, "cert_code");
				ElementUtils.setXMLElementValue(outMessage, xpathOutput, cx_sign, "cx_sign");
				ElementUtils.setXMLElementValue(outMessage, xpathOutput, establish_date, "establish_date");
				ElementUtils.setXMLElementValue(outMessage, xpathOutput, available_date, "available_date");
				ElementUtils.setXMLElementValue(outMessage, xpathOutput, remark, "remark");
				ElementUtils.setXMLElementValue(outMessage, xpathOutput, current_balance, "current_balance");
				ElementUtils.setXMLElementValue(outMessage, xpathOutput, freezed_balance, "freezed_balance");
				ElementUtils.setXMLElementValue(outMessage, xpathOutput, available_balance, "available_balance");
				ElementUtils.setXMLElementValue(outMessage, xpathOutput, create_by, "create_by");
				ElementUtils.setXMLElementValue(outMessage, xpathOutput, create_time, "create_time");
				ElementUtils.setXMLElementValue(outMessage, xpathOutput, update_by, "update_by");
				ElementUtils.setXMLElementValue(outMessage, xpathOutput, update_time, "update_time");
				ElementUtils.setXMLElementValue(outMessage, xpathOutput, ledger_balance, "ledger_balance");
				ElementUtils.setXMLElementValue(outMessage, xpathOutput, hold_amt, "hold_amt");
				ElementUtils.setXMLElementValue(outMessage, xpathOutput, overdraft_limit, "overdraft_limit");
				ElementUtils.setXMLElementValue(outMessage, xpathOutput, interest_rate, "interest_rate");
				ElementUtils.setXMLElementValue(outMessage, xpathOutput, date_acct_opened, "date_acct_opened");
				ElementUtils.setXMLElementValue(outMessage, xpathOutput, passbook_no, "passbook_no");
				ElementUtils.setXMLElementValue(outMessage, xpathOutput, accured_interest, "accured_interest");
				ElementUtils.setXMLElementValue(outMessage, xpathOutput, term, "term");
				ElementUtils.setXMLElementValue(outMessage, xpathOutput, ori_balance, "ori_balance");

				ElementUtils.setXMLElementValue(outMessage, xpathOutput, principal_balance, "principal_balance");
				ElementUtils.setXMLElementValue(outMessage, xpathOutput, penalty_amt, "penalty_amt");
				ElementUtils.setXMLElementValue(outMessage, xpathOutput, current_cash_value, "current_cash_value");
				ElementUtils.setXMLElementValue(outMessage, xpathOutput, earmarked_amt, "earmarked_amt");
				ElementUtils.setXMLElementValue(outMessage, xpathOutput, issued_date, "issued_date");
				ElementUtils.setXMLElementValue(outMessage, xpathOutput, maturity_date, "maturity_date");
				ElementUtils.setXMLElementValue(outMessage, xpathOutput, times_nenewed_count, "times_nenewed_count");
				ElementUtils.setXMLElementValue(outMessage, xpathOutput, purpose_code, "purpose_code");
				ElementUtils.setXMLElementValue(outMessage, xpathOutput, loan_ori_amt, "loan_ori_amt");
				ElementUtils.setXMLElementValue(outMessage, xpathOutput, os_principal, "os_principal");
				ElementUtils.setXMLElementValue(outMessage, xpathOutput, os_balance, "os_balance");
				ElementUtils.setXMLElementValue(outMessage, xpathOutput, loan_term, "loan_term");

				ElementUtils.setXMLElementValue(outMessage, xpathOutput, principal_frequent, "principal_frequent");
				ElementUtils.setXMLElementValue(outMessage, xpathOutput, interest_frequent, "interest_frequent");
				ElementUtils.setXMLElementValue(outMessage, xpathOutput, full_release_date, "full_release_date");
				ElementUtils.setXMLElementValue(outMessage, xpathOutput, overdue_indicator_desc, "overdue_indicator_desc");
				// Kienvt mapping de lay dung status
				acct_status = CoreBankUtils.mappingAccountStatus(acct_type, acct_status);
				ElementUtils.setXMLElementValue(outMessage, xpathOutput, acct_status, "acct_status");

				// ElementUtils.setXMLElementValue(outMessage, xpathOutput,
				// billed_total_amt, "billed_total_amt");
				ElementUtils.setXMLElementValue(outMessage, xpathOutput, billed_principal, "billed_principal");
				ElementUtils.setXMLElementValue(outMessage, xpathOutput, billed_interest, "billed_interest");
				ElementUtils.setXMLElementValue(outMessage, xpathOutput, billed_late_charge, "billed_late_charge");
				ElementUtils.setXMLElementValue(outMessage, xpathOutput, payment_amt, "payment_amt");
				ElementUtils.setXMLElementValue(outMessage, xpathOutput, final_payment_amt, "final_payment_amt");
			}
			this.hostMessageLogInfo.setResp_code(String.valueOf(retErrorInfo.getErrorCode()));
			this.hostMessageLogInfo.setResp_msg(retErrorInfo.getErrorMessage());
			this.hostMessageLogInfo.setHostRequestMsg("[" + hostRequestMessage + "]");
			this.hostMessageLogInfo.setHostResponseMsg("[" + hostResponseMessage + "]");
			this.arrRetHOSTMessageLogInfo.add(hostMessageLogInfo);
		} catch (Exception ex) {
			ex.printStackTrace();
			logger.error(new StringBuffer().append("Error source:").append(CLASS_NAME + ".getAccount()\n").append("Error message:").append(ex.toString() + "\n"));
			this.retErrorInfo.setErrorCode(Global.ERR_SYSTEM_UNKNOWN_ERROR);
			this.retErrorInfo.setErrorMessage(ex.toString());
		}
	}

	/**
	 * 
	 * @param cif_no
	 */
	private void getListOfCustomerAccount(String cif_no) {
		try {
			String acct_type = "", acct_no = "", acct_ccy = "";
			String sub_acct_type = "", acct_name = "", p_acct_no = "", sub_branch_no = "";
			String cb_sign = "", cx_sign = "", establish_date = "", available_date = "";
			String branch_no = "", cert_type = "", cert_code = "", remark = "";
			String current_balance = "", freezed_balance = "", available_balance = "", create_by = "";
			String create_time = "", update_by = "", update_time = "", ledger_balance = "";
			String hold_amt = "", overdraft_limit = "", interest_rate = "";
			String date_acct_opened = "", passbook_no = "", accured_interest = "", term = "";
			String ori_balance = "", principal_balance = "", penalty_amt = "", current_cash_value = "";
			String earmarked_amt = "", issued_date = "", maturity_date = "";
			String times_nenewed_count = "", purpose_code = "", loan_ori_amt = "", os_balance = "";
			String loan_term = "", principal_frequent = "", interest_frequent = "", full_release_date = "";
			String overdue_indicator_desc = "", loan_term_code = "", acct_status = "", product_code = "";
			String billed_late_charge = "", billed_principal = "", billed_interest = "", payment_amt = "", final_payment_amt = "";
			String billed_other_charge = "", billed_misc_charge = "";
			String accured_interest_due = "", os_principal = "";

			String hostRequestMessage = "";
			String hostResponseMessage = "";
			MBASE_TEMPLATE[2] = hostMessageLogInfo.getWs_ip();
			MBASE_TEMPLATE[25] = hostMessageLogInfo.getTeller_id();
			MBASE_TEMPLATE[26] = hostMessageLogInfo.getWs_name();
			MBASE_TEMPLATE[32] = hostMessageLogInfo.getApprover_id();
			MBASE_TEMPLATE[40] = hostMessageLogInfo.getWs_name();
			MBASE_TEMPLATE[42] = hostMessageLogInfo.getBranch_code();
			final int MAX_RECORD_RETRIEVE = 30;
			MBASE_TEMPLATE[23] = String.valueOf(MAX_RECORD_RETRIEVE);

			int startPos = 69, recordLength = 23;
			if (cif_no.length() > 0) {
				rebuildTransactionInfo(SIBS_009, Global.APP_DEFAULT_BRANCH_CODE);
				MBASE_TEMPLATE[18] = "BBMBSCFINQFNC";// scenarioNumber
				MBASE_TEMPLATE[27] = this.hostMessageLogInfo.getHost_tran_code();// "15999";
				MBASE_TEMPLATE[46] = this.hostMessageLogInfo.getHost_tran_code();// "15999";
				MBASE_TEMPLATE[66] = cif_no;
				MBASE_TEMPLATE[68] = cif_no;
			}
			// String hasMoreRecord = "";
			hostRequestMessage = AppUtils.convertArrayToString(MBASE_TEMPLATE);
			this.hostMessageLogInfo.setSend_time(AppUtils.now(Global.DEF_FORMAT_DATE_TIME_FULL));
			try {
				retMessage = as400Port.hostMessageSending(hostMessageLogInfo.getRef_channel(), hostRequestMessage);
			} catch (RemoteException ex) {
				this.retErrorInfo.setErrorCode(Global.ERR_CM_EXCEPTION_WHEN_CALL_ONECONNECT);
				this.retErrorInfo.setErrorMessage(ex.toString());
			}
			this.hostMessageLogInfo.setReceive_time(AppUtils.now(Global.DEF_FORMAT_DATE_TIME_FULL));
			ArrayList<String[]> retArrOfResult = null;
			// ArrayList<String[]> tempretArrOfResult = null;
			if (retMessage != null) {
				hostResponseMessage = AppUtils.convertArrayToString(retMessage.getArrString());

				if (retMessage.getErrCode() == null) {
					retArrOfResult = AppUtils.getListOfResponseRow(retMessage.getArrString(), startPos, recordLength);
					// hasMoreRecord = retMessage.getArrString()[9];
				} else {
					this.retErrorInfo.setErrorCode(Global.ERR_MBASE_START);
					this.retErrorInfo.setErrorMessage(retMessage.getDescription());
				}
			} else {
				this.retErrorInfo.setErrorCode(Global.ERR_CM_EXCEPTION_WHEN_CALL_ONECONNECT);
				this.retErrorInfo.setErrorMessage("ERR_CM_EXCEPTION_WHEN_CALL_ONECONNECT");
			}
			// System.arraycopy(tempretArrOfResult, 0, retArrOfResult, 0,
			// tempretArrOfResult.size());

			if (retArrOfResult != null && retArrOfResult.size() > 0) {
				// 1.Tao node list,entity
				String xpathOutput = "/message/?body/?list[?@name[set-value('records')]]";
				ElementUtils.setXMLElementValue(outMessage, xpathOutput);

				for (int i = 0; i < retArrOfResult.size(); i++) {
					// 1.Loai bo cac join account
					// 2.Loai bo cac FD account (chi lay fd receipt)
					if (!retArrOfResult.get(i)[3].equals("JA") && !retArrOfResult.get(i)[8].equals(Global.COREBBANK_FD_GROUP_ACCOUNT_TYPE)) {

						// 2.Tao cac field
						xpathOutput = "/message/body/list[@name='records']/?$entity[?@name[set-value('" + i + "')]]";
						ElementUtils.setXMLElementValue(outMessage, xpathOutput);
						xpathOutput = "/message/body/list[@name='records']/entity[@name='%s']/?$field[set-value('%s')][?@name[set-value('%s')]]";
						ElementUtils.setXMLElementValue(outMessage, xpathOutput, String.valueOf(i), retArrOfResult.get(i)[14], "cif_no");
						ElementUtils.setXMLElementValue(outMessage, xpathOutput, String.valueOf(i), CoreBankUtils.correctAccountNumber(retArrOfResult.get(i)[2]), "acct_no");
						ElementUtils.setXMLElementValue(outMessage, xpathOutput, String.valueOf(i), retArrOfResult.get(i)[9], "acct_ccy");
						ElementUtils.setXMLElementValue(outMessage, xpathOutput, String.valueOf(i), retArrOfResult.get(i)[8], "acct_type");
						ElementUtils.setXMLElementValue(outMessage, xpathOutput, String.valueOf(i), sub_acct_type, "sub_acct_type");
						ElementUtils.setXMLElementValue(outMessage, xpathOutput, String.valueOf(i), retArrOfResult.get(i)[20], "acct_name");
						ElementUtils.setXMLElementValue(outMessage, xpathOutput, String.valueOf(i), p_acct_no, "p_acct_no");
						ElementUtils.setXMLElementValue(outMessage, xpathOutput, String.valueOf(i), CoreBankUtils.correctBranchCode(branch_no), "branch_no");
						ElementUtils.setXMLElementValue(outMessage, xpathOutput, String.valueOf(i), sub_branch_no, "sub_branch_no");
						ElementUtils.setXMLElementValue(outMessage, xpathOutput, String.valueOf(i), cb_sign, "cb_sign");
						ElementUtils.setXMLElementValue(outMessage, xpathOutput, String.valueOf(i), retArrOfResult.get(i)[16], "cert_type");
						ElementUtils.setXMLElementValue(outMessage, xpathOutput, String.valueOf(i), retArrOfResult.get(i)[17], "cert_code");
						ElementUtils.setXMLElementValue(outMessage, xpathOutput, String.valueOf(i), cx_sign, "cx_sign");
						ElementUtils.setXMLElementValue(outMessage, xpathOutput, String.valueOf(i), establish_date, "establish_date");
						ElementUtils.setXMLElementValue(outMessage, xpathOutput, String.valueOf(i), available_date, "available_date");
						ElementUtils.setXMLElementValue(outMessage, xpathOutput, String.valueOf(i), remark, "remark");
						ElementUtils.setXMLElementValue(outMessage, xpathOutput, String.valueOf(i), current_balance, "current_balance");
						ElementUtils.setXMLElementValue(outMessage, xpathOutput, String.valueOf(i), freezed_balance, "freezed_balance");
						ElementUtils.setXMLElementValue(outMessage, xpathOutput, String.valueOf(i), retArrOfResult.get(i)[7], "available_balance");
						ElementUtils.setXMLElementValue(outMessage, xpathOutput, String.valueOf(i), create_by, "create_by");
						ElementUtils.setXMLElementValue(outMessage, xpathOutput, String.valueOf(i), create_time, "create_time");
						ElementUtils.setXMLElementValue(outMessage, xpathOutput, String.valueOf(i), update_by, "update_by");
						ElementUtils.setXMLElementValue(outMessage, xpathOutput, String.valueOf(i), update_time, "update_time");
						ElementUtils.setXMLElementValue(outMessage, xpathOutput, String.valueOf(i), ledger_balance, "ledger_balance");
						ElementUtils.setXMLElementValue(outMessage, xpathOutput, String.valueOf(i), hold_amt, "hold_amt");
						ElementUtils.setXMLElementValue(outMessage, xpathOutput, String.valueOf(i), overdraft_limit, "overdraft_limit");
						ElementUtils.setXMLElementValue(outMessage, xpathOutput, String.valueOf(i), interest_rate, "interest_rate");
						ElementUtils.setXMLElementValue(outMessage, xpathOutput, String.valueOf(i), date_acct_opened, "date_acct_opened");
						ElementUtils.setXMLElementValue(outMessage, xpathOutput, String.valueOf(i), passbook_no, "passbook_no");
						ElementUtils.setXMLElementValue(outMessage, xpathOutput, String.valueOf(i), accured_interest, "accured_interest");
						ElementUtils.setXMLElementValue(outMessage, xpathOutput, String.valueOf(i), term, "term");
						ElementUtils.setXMLElementValue(outMessage, xpathOutput, String.valueOf(i), ori_balance, "ori_balance");
						ElementUtils.setXMLElementValue(outMessage, xpathOutput, String.valueOf(i), principal_balance, "principal_balance");
						ElementUtils.setXMLElementValue(outMessage, xpathOutput, String.valueOf(i), penalty_amt, "penalty_amt");
						ElementUtils.setXMLElementValue(outMessage, xpathOutput, String.valueOf(i), current_cash_value, "current_cash_value");
						ElementUtils.setXMLElementValue(outMessage, xpathOutput, String.valueOf(i), earmarked_amt, "earmarked_amt");
						ElementUtils.setXMLElementValue(outMessage, xpathOutput, String.valueOf(i), issued_date, "issued_date");
						ElementUtils.setXMLElementValue(outMessage, xpathOutput, String.valueOf(i), maturity_date, "maturity_date");
						ElementUtils.setXMLElementValue(outMessage, xpathOutput, String.valueOf(i), times_nenewed_count, "times_nenewed_count");
						ElementUtils.setXMLElementValue(outMessage, xpathOutput, String.valueOf(i), purpose_code, "purpose_code");
						ElementUtils.setXMLElementValue(outMessage, xpathOutput, String.valueOf(i), loan_ori_amt, "loan_ori_amt");
						ElementUtils.setXMLElementValue(outMessage, xpathOutput, String.valueOf(i), os_balance, "os_balance");
						ElementUtils.setXMLElementValue(outMessage, xpathOutput, String.valueOf(i), os_principal, "os_principal");
						ElementUtils.setXMLElementValue(outMessage, xpathOutput, String.valueOf(i), loan_term, "loan_term");
						ElementUtils.setXMLElementValue(outMessage, xpathOutput, String.valueOf(i), principal_frequent, "principal_frequent");
						ElementUtils.setXMLElementValue(outMessage, xpathOutput, String.valueOf(i), interest_frequent, "interest_frequent");
						ElementUtils.setXMLElementValue(outMessage, xpathOutput, String.valueOf(i), full_release_date, "full_release_date");
						ElementUtils.setXMLElementValue(outMessage, xpathOutput, String.valueOf(i), overdue_indicator_desc, "overdue_indicator_desc");
						// Kienvt mapping de lay dung status
						acct_status = CoreBankUtils.mappingAccountStatus(retArrOfResult.get(i)[1], retArrOfResult.get(i)[11]);
						ElementUtils.setXMLElementValue(outMessage, xpathOutput, String.valueOf(i), acct_status, "acct_status");
						ElementUtils.setXMLElementValue(outMessage, xpathOutput, String.valueOf(i), loan_term_code, "loan_term_code");
						ElementUtils.setXMLElementValue(outMessage, xpathOutput, String.valueOf(i), billed_late_charge, "billed_late_charge");
						ElementUtils.setXMLElementValue(outMessage, xpathOutput, String.valueOf(i), billed_principal, "billed_principal");
						ElementUtils.setXMLElementValue(outMessage, xpathOutput, String.valueOf(i), billed_interest, "billed_interest");
						ElementUtils.setXMLElementValue(outMessage, xpathOutput, String.valueOf(i), payment_amt, "payment_amt");
						ElementUtils.setXMLElementValue(outMessage, xpathOutput, String.valueOf(i), final_payment_amt, "final_payment_amt");
					}
				}
			}
			this.hostMessageLogInfo.setResp_code(String.valueOf(retErrorInfo.getErrorCode()));
			this.hostMessageLogInfo.setResp_msg(retErrorInfo.getErrorMessage());
			this.hostMessageLogInfo.setHostRequestMsg("[" + hostRequestMessage + "]");
			this.hostMessageLogInfo.setHostResponseMsg("[" + hostResponseMessage + "]");
			this.arrRetHOSTMessageLogInfo.add(hostMessageLogInfo);
		} catch (Exception ex) {
			ex.printStackTrace();
			logger
					.error(new StringBuffer().append("Error source:").append(CLASS_NAME + ".getListOfCustomerAccount()\n").append("Error message:").append(
							ex.getStackTrace() + "\n"));
			this.retErrorInfo.setErrorCode(Global.ERR_SYSTEM_UNKNOWN_ERROR);
			this.retErrorInfo.setErrorMessage(ex.getMessage());
		}
	}

	private void getListOfCustomerAccountOffline(String cif_no) {
		try {
			AccountInfoFacade acctFacade = new AccountInfoFacade();
			String hostRequestMessage = "";
			String hostResponseMessage = "";
			ArrayList<AccountInfo> arrAccountInfo = null;
			this.hostMessageLogInfo.setSend_time(AppUtils.now(Global.DEF_FORMAT_DATE_TIME_FULL));
			try {
				if (cif_no.length() > 0) {
					rebuildTransactionInfo(SIBS_009, Global.APP_DEFAULT_BRANCH_CODE);
					arrAccountInfo = acctFacade.getAccountInfoByCif(cif_no);
				} else {

				}
			} catch (Exception ex) {
				this.retErrorInfo.setErrorCode(Global.ERR_CM_EXCEPTION_WHEN_CALL_ONECONNECT);
				this.retErrorInfo.setErrorMessage(ex.toString());
			}
			this.hostMessageLogInfo.setReceive_time(AppUtils.now(Global.DEF_FORMAT_DATE_TIME_FULL));

			if (arrAccountInfo == null || arrAccountInfo.size() == 0) {
				this.retErrorInfo.setErrorCode(Global.ERR_MBASE_START);
				this.retErrorInfo.setErrorMessage("No record found");
			} else {

				// 1.Tao node list,entity
				String xpathOutput = "/message/?body/?list[?@name[set-value('records')]]";
				ElementUtils.setXMLElementValue(outMessage, xpathOutput);

				for (int i = 0; i < arrAccountInfo.size(); i++) {
					AccountInfo tempAccount = arrAccountInfo.get(i);
					xpathOutput = "/message/body/list[@name='records']/?$entity[?@name[set-value('" + i + "')]]";
					ElementUtils.setXMLElementValue(outMessage, xpathOutput);
					xpathOutput = "/message/body/list[@name='records']/entity[@name='%s']/?$field[set-value('%s')][?@name[set-value('%s')]]";

					ElementUtils.setXMLElementValue(outMessage, xpathOutput, String.valueOf(i), tempAccount.getCif_no(), "cif_no");
					ElementUtils.setXMLElementValue(outMessage, xpathOutput, String.valueOf(i), CoreBankUtils.correctAccountNumber(tempAccount.getAccount_no()), "acct_no");
					ElementUtils.setXMLElementValue(outMessage, xpathOutput, String.valueOf(i), tempAccount.getAcct_ccy(), "acct_ccy");
					ElementUtils.setXMLElementValue(outMessage, xpathOutput, String.valueOf(i), tempAccount.getAcct_type(), "acct_type");
					ElementUtils.setXMLElementValue(outMessage, xpathOutput, String.valueOf(i), tempAccount.getSub_acct_type(), "sub_acct_type");
					ElementUtils.setXMLElementValue(outMessage, xpathOutput, String.valueOf(i), AppUtils.XMLReplaceSpecChar(tempAccount.getAcct_name()), "acct_name");
					ElementUtils.setXMLElementValue(outMessage, xpathOutput, String.valueOf(i), CoreBankUtils.correctAccountNumber(tempAccount.getP_acct_no()), "p_acct_no");
					ElementUtils.setXMLElementValue(outMessage, xpathOutput, String.valueOf(i), CoreBankUtils.correctBranchCode(tempAccount.getBranch_no()), "branch_no");
					ElementUtils.setXMLElementValue(outMessage, xpathOutput, String.valueOf(i), tempAccount.getSub_branch_no(), "sub_branch_no");
					ElementUtils.setXMLElementValue(outMessage, xpathOutput, String.valueOf(i), tempAccount.getCb_sign(), "cb_sign");
					ElementUtils.setXMLElementValue(outMessage, xpathOutput, String.valueOf(i), tempAccount.getCert_type(), "cert_type");
					ElementUtils.setXMLElementValue(outMessage, xpathOutput, String.valueOf(i), tempAccount.getCert_code(), "cert_code");
					ElementUtils.setXMLElementValue(outMessage, xpathOutput, String.valueOf(i), tempAccount.getCx_sign(), "cx_sign");
					ElementUtils.setXMLElementValue(outMessage, xpathOutput, String.valueOf(i), CoreBankUtils.convertCB2EBDate(tempAccount.getEstablish_date()), "establish_date");
					ElementUtils.setXMLElementValue(outMessage, xpathOutput, String.valueOf(i), CoreBankUtils.convertCB2EBDate(tempAccount.getAvailable_date()), "available_date");
					ElementUtils.setXMLElementValue(outMessage, xpathOutput, String.valueOf(i), tempAccount.getRemark(), "remark");
					ElementUtils.setXMLElementValue(outMessage, xpathOutput, String.valueOf(i), tempAccount.getCurrent_balance(), "current_balance");
					ElementUtils.setXMLElementValue(outMessage, xpathOutput, String.valueOf(i), tempAccount.getFreezed_balance(), "freezed_balance");
					ElementUtils.setXMLElementValue(outMessage, xpathOutput, String.valueOf(i), tempAccount.getAvailable_balance(), "available_balance");
					ElementUtils.setXMLElementValue(outMessage, xpathOutput, String.valueOf(i), tempAccount.getCreate_by(), "create_by");
					ElementUtils.setXMLElementValue(outMessage, xpathOutput, String.valueOf(i), tempAccount.getCreate_time(), "create_time");
					ElementUtils.setXMLElementValue(outMessage, xpathOutput, String.valueOf(i), tempAccount.getUpdate_by(), "update_by");
					ElementUtils.setXMLElementValue(outMessage, xpathOutput, String.valueOf(i), tempAccount.getUpdate_time(), "update_time");
					ElementUtils.setXMLElementValue(outMessage, xpathOutput, String.valueOf(i), tempAccount.getLedger_balance(), "ledger_balance");
					ElementUtils.setXMLElementValue(outMessage, xpathOutput, String.valueOf(i), tempAccount.getHold_amt(), "hold_amt");
					ElementUtils.setXMLElementValue(outMessage, xpathOutput, String.valueOf(i), tempAccount.getOverdraft_limit(), "overdraft_limit");
					ElementUtils.setXMLElementValue(outMessage, xpathOutput, String.valueOf(i), tempAccount.getInterest_rate(), "interest_rate");
					ElementUtils.setXMLElementValue(outMessage, xpathOutput, String.valueOf(i), CoreBankUtils.convertCB2EBDate(tempAccount.getDate_acct_opened()),
							"date_acct_opened");
					ElementUtils.setXMLElementValue(outMessage, xpathOutput, String.valueOf(i), tempAccount.getPassbook_no(), "passbook_no");
					ElementUtils.setXMLElementValue(outMessage, xpathOutput, String.valueOf(i), tempAccount.getAccured_interest(), "accured_interest");
					ElementUtils.setXMLElementValue(outMessage, xpathOutput, String.valueOf(i), tempAccount.getTerm(), "term");
					ElementUtils.setXMLElementValue(outMessage, xpathOutput, String.valueOf(i), tempAccount.getOri_balance(), "ori_balance");
					ElementUtils.setXMLElementValue(outMessage, xpathOutput, String.valueOf(i), tempAccount.getPrincipal_balance(), "principal_balance");
					ElementUtils.setXMLElementValue(outMessage, xpathOutput, String.valueOf(i), tempAccount.getPenalty_amt(), "penalty_amt");
					ElementUtils.setXMLElementValue(outMessage, xpathOutput, String.valueOf(i), tempAccount.getCurrent_cash_value(), "current_cash_value");
					ElementUtils.setXMLElementValue(outMessage, xpathOutput, String.valueOf(i), tempAccount.getEarmarked_amt(), "earmarked_amt");
					ElementUtils.setXMLElementValue(outMessage, xpathOutput, String.valueOf(i), CoreBankUtils.convertCB2EBDate(tempAccount.getIssued_date()), "issued_date");
					ElementUtils.setXMLElementValue(outMessage, xpathOutput, String.valueOf(i), CoreBankUtils.convertCB2EBDate(tempAccount.getMaturity_date()), "maturity_date");
					ElementUtils.setXMLElementValue(outMessage, xpathOutput, String.valueOf(i), tempAccount.getTimes_nenewed_count(), "times_nenewed_count");
					ElementUtils.setXMLElementValue(outMessage, xpathOutput, String.valueOf(i), tempAccount.getPurpose_code(), "purpose_code");
					ElementUtils.setXMLElementValue(outMessage, xpathOutput, String.valueOf(i), tempAccount.getLoan_ori_amt(), "loan_ori_amt");
					ElementUtils.setXMLElementValue(outMessage, xpathOutput, String.valueOf(i), tempAccount.getOs_balance(), "os_balance");
					ElementUtils.setXMLElementValue(outMessage, xpathOutput, String.valueOf(i), tempAccount.getOs_principal(), "os_principal");
					ElementUtils.setXMLElementValue(outMessage, xpathOutput, String.valueOf(i), tempAccount.getLoan_term(), "loan_term");
					ElementUtils.setXMLElementValue(outMessage, xpathOutput, String.valueOf(i), tempAccount.getPrincipal_frequent(), "principal_frequent");
					ElementUtils.setXMLElementValue(outMessage, xpathOutput, String.valueOf(i), tempAccount.getInterest_frequent(), "interest_frequent");
					ElementUtils.setXMLElementValue(outMessage, xpathOutput, String.valueOf(i), tempAccount.getFull_release_date(), "full_release_date");
					ElementUtils.setXMLElementValue(outMessage, xpathOutput, String.valueOf(i), tempAccount.getOverdue_indicator_desc(), "overdue_indicator_desc");
					ElementUtils.setXMLElementValue(outMessage, xpathOutput, String.valueOf(i), tempAccount.getAcct_status(), "acct_status");
					ElementUtils.setXMLElementValue(outMessage, xpathOutput, String.valueOf(i), tempAccount.getLoan_term_code(), "loan_term_code");
					ElementUtils.setXMLElementValue(outMessage, xpathOutput, String.valueOf(i), tempAccount.getBilled_late_charge(), "billed_late_charge");
					ElementUtils.setXMLElementValue(outMessage, xpathOutput, String.valueOf(i), tempAccount.getBilled_principal(), "billed_principal");
					ElementUtils.setXMLElementValue(outMessage, xpathOutput, String.valueOf(i), tempAccount.getBilled_interest(), "billed_interest");
					// ElementUtils.setXMLElementValue(outMessage, xpathOutput,
					// String.valueOf(i), tempAccount.getBilled_total_amt(),
					// "billed_total_amt");
					ElementUtils.setXMLElementValue(outMessage, xpathOutput, String.valueOf(i), tempAccount.getPayment_amt(), "payment_amt");
					ElementUtils.setXMLElementValue(outMessage, xpathOutput, String.valueOf(i), tempAccount.getFinal_payment_amt(), "final_payment_amt");
				}
			}
			this.hostMessageLogInfo.setResp_code(String.valueOf(retErrorInfo.getErrorCode()));
			this.hostMessageLogInfo.setResp_msg(retErrorInfo.getErrorMessage());
			this.hostMessageLogInfo.setHostRequestMsg("[" + hostRequestMessage + "]");
			this.hostMessageLogInfo.setHostResponseMsg("[" + hostResponseMessage + "]");
			this.arrRetHOSTMessageLogInfo.add(hostMessageLogInfo);
		} catch (Exception ex) {
			ex.printStackTrace();
			logger.error(new StringBuffer().append("Error source:").append(CLASS_NAME + ".getListOfCustomerAccountOffline()\n").append("Error message:").append(
					ex.getStackTrace() + "\n"));
			this.retErrorInfo.setErrorCode(Global.ERR_SYSTEM_UNKNOWN_ERROR);
			this.retErrorInfo.setErrorMessage(ex.getMessage());
		}
	}

	/**
	 * (TR004)Create cash flow transaction
	 * 
	 * Reference: SIBS_043
	 * 
	 * @author Vu Trung Kien
	 * @version 1.0
	 */
	private void createCashFlowOrder() {
		try {
			String xpathInput = "/message/body/field[@name='%s']";
			// Thieu branch code???
			String major_acct_no = ElementUtils.getXMLElementInStringValue(inMessage, String.format(xpathInput, "major_acct_no"));
			String major_acct_type = ElementUtils.getXMLElementInStringValue(inMessage, String.format(xpathInput, "major_acct_type"));
			String sub_acct_no = ElementUtils.getXMLElementInStringValue(inMessage, String.format(xpathInput, "sub_acct_no"));
			String sub_acct_type = ElementUtils.getXMLElementInStringValue(inMessage, String.format(xpathInput, "sub_acct_type"));
			String ceiling_amt = CoreBankUtils.roundCBNumberic(ElementUtils.getXMLElementInStringValue(inMessage, String.format(xpathInput, "ceiling_amt")));
			String floor_amt = CoreBankUtils.roundCBNumberic(ElementUtils.getXMLElementInStringValue(inMessage, String.format(xpathInput, "floor_amt")));
			String balance_type = ElementUtils.getXMLElementInStringValue(inMessage, String.format(xpathInput, "balance_type"));
			String fee = CoreBankUtils.roundCBNumberic(ElementUtils.getXMLElementInStringValue(inMessage, String.format(xpathInput, "fee")));

			if (major_acct_no.length() == 0) {
				this.retErrorInfo.setErrorCode(Global.ERR_UDF_SRC_ACCOUNT_NO_NOT_VALID_OR_MISSING);
				this.retErrorInfo.setErrorMessage("ERR_UDF_SRC_ACCOUNT_NO_NOT_VALID_OR_MISSING");
				return;
			}
			if (major_acct_type.length() == 0 || CoreBankUtils.isValidAccountType(major_acct_type) == false) {
				this.retErrorInfo.setErrorCode(Global.ERR_UDF_SRC_ACCOUNT_TYPE_NOT_VALID_OR_MISSING);
				this.retErrorInfo.setErrorMessage("ERR_UDF_SRC_ACCOUNT_TYPE_NOT_VALID_OR_MISSING");
				return;
			}
			if (sub_acct_no.length() == 0) {
				this.retErrorInfo.setErrorCode(Global.ERR_UDF_DES_ACCOUNT_NO_NOT_VALID_OR_MISSING);
				this.retErrorInfo.setErrorMessage("ERR_UDF_DES_ACCOUNT_NO_NOT_VALID_OR_MISSING");
				return;
			}
			if (sub_acct_type.length() == 0 || CoreBankUtils.isValidAccountType(sub_acct_type) == false) {
				this.retErrorInfo.setErrorCode(Global.ERR_UDF_DES_ACCOUNT_TYPE_NOT_VALID_OR_MISSING);
				this.retErrorInfo.setErrorMessage("ERR_UDF_DES_ACCOUNT_TYPE_NOT_VALID_OR_MISSING");
				return;
			}
			if (!CoreBankUtils.isValidTransactionAmount(ceiling_amt)) {
				this.retErrorInfo.setErrorCode(Global.ERR_UDF_CEILLING_AMT_NOT_VALID_OR_MISSING);
				this.retErrorInfo.setErrorMessage("ERR_UDF_CEILLING_AMT_NOT_VALID_OR_MISSING");
				return;
			}
			if (!CoreBankUtils.isValidTransactionAmount(floor_amt)) {
				this.retErrorInfo.setErrorCode(Global.ERR_UDF_FLOOR_AMT_NOT_VALID_OR_MISSING);
				this.retErrorInfo.setErrorMessage("ERR_UDF_FLOOR_AMT_NOT_VALID_OR_MISSING");
				return;
			}
			if (balance_type.length() == 0) {
				this.retErrorInfo.setErrorCode(Global.ERR_UDF_BALANCE_TYPE_NOT_VALID_OR_MISSING);
				this.retErrorInfo.setErrorMessage("ERR_UDF_BALANCE_TYPE_NOT_VALID_OR_MISSING");
				return;
			}
			rebuildTransactionInfo(SIBS_010, Global.APP_DEFAULT_BRANCH_CODE);
			MBASE_TEMPLATE[47] = "A";// Add
			MBASE_TEMPLATE[48] = "R";// 
			MBASE_TEMPLATE[49] = "1";// numOfRecord
			MBASE_TEMPLATE[50] = "N";// 
			MBASE_TEMPLATE[51] = "F";// 

			MBASE_TEMPLATE[68] = major_acct_no;
			MBASE_TEMPLATE[69] = major_acct_type;
			MBASE_TEMPLATE[70] = sub_acct_no;
			MBASE_TEMPLATE[71] = sub_acct_type;
			MBASE_TEMPLATE[72] = ceiling_amt + BASED_TRADE_UNIT;
			MBASE_TEMPLATE[73] = floor_amt + BASED_TRADE_UNIT;
			MBASE_TEMPLATE[74] = balance_type;
			MBASE_TEMPLATE[75] = "Y";// Auto reset
			MBASE_TEMPLATE[76] = fee + BASED_TRADE_UNIT;

			MBASE_TEMPLATE[2] = hostMessageLogInfo.getWs_ip();
			MBASE_TEMPLATE[18] = "BBMBSDDMNTFNC";// scenarioNumber
			MBASE_TEMPLATE[25] = hostMessageLogInfo.getTeller_id();
			MBASE_TEMPLATE[26] = hostMessageLogInfo.getWs_name();
			MBASE_TEMPLATE[32] = hostMessageLogInfo.getApprover_id();
			MBASE_TEMPLATE[40] = hostMessageLogInfo.getWs_name();
			MBASE_TEMPLATE[42] = hostMessageLogInfo.getBranch_code();
			MBASE_TEMPLATE[27] = this.hostMessageLogInfo.getHost_tran_code();// "28131";
			MBASE_TEMPLATE[46] = this.hostMessageLogInfo.getHost_tran_code();// "28131";

			String hostRequestMessage = AppUtils.convertArrayToString(MBASE_TEMPLATE);
			String hostResponseMessage = "";
			this.hostMessageLogInfo.setSend_time(AppUtils.now(Global.DEF_FORMAT_DATE_TIME_FULL));
			try {
				retMessage = as400Port.hostMessageSending(hostMessageLogInfo.getRef_channel(), hostRequestMessage);
			} catch (RemoteException ex) {
				this.retErrorInfo.setErrorCode(Global.ERR_CM_EXCEPTION_WHEN_CALL_ONECONNECT);
				this.retErrorInfo.setErrorMessage(ex.toString());
			}
			this.hostMessageLogInfo.setReceive_time(AppUtils.now(Global.DEF_FORMAT_DATE_TIME_FULL));
			if (retMessage != null) {
				if (retMessage.getErrCode() == null) {
					String xpathOutput = "/message/?body/?$field[set-value('%s')][?@name[set-value('%s')]]";
					ElementUtils.setXMLElementValue(outMessage, xpathOutput, CoreBankUtils.correctAccountNumber(major_acct_no), "major_acct_no");
					ElementUtils.setXMLElementValue(outMessage, xpathOutput, major_acct_type, "major_acct_type");
					ElementUtils.setXMLElementValue(outMessage, xpathOutput, CoreBankUtils.correctAccountNumber(sub_acct_no), "sub_acct_no");
					ElementUtils.setXMLElementValue(outMessage, xpathOutput, sub_acct_type, "sub_acct_type");
					ElementUtils.setXMLElementValue(outMessage, xpathOutput, ceiling_amt, "ceiling_amt");
					ElementUtils.setXMLElementValue(outMessage, xpathOutput, floor_amt, "floor_amt");
					ElementUtils.setXMLElementValue(outMessage, xpathOutput, balance_type, "balance_type");
					ElementUtils.setXMLElementValue(outMessage, xpathOutput, fee, "fee");
				} else {
					this.retErrorInfo.setErrorCode(Global.ERR_MBASE_START);
					this.retErrorInfo.setErrorMessage(retMessage.getDescription());
					this.retErrorInfo.setErrorType(MESSAGE_TYPE_MBASE);
				}
				hostResponseMessage = AppUtils.convertArrayToString(retMessage.getArrString());
			}

			this.hostMessageLogInfo.setResp_code(String.valueOf(retErrorInfo.getErrorCode()));
			this.hostMessageLogInfo.setResp_msg(retErrorInfo.getErrorMessage());
			this.hostMessageLogInfo.setHostRequestMsg("[" + hostRequestMessage + "]");
			this.hostMessageLogInfo.setHostResponseMsg("[" + hostResponseMessage + "]");
			this.arrRetHOSTMessageLogInfo.add(hostMessageLogInfo);

		} catch (Exception ex) {
			ex.printStackTrace();
			logger.error(new StringBuffer().append("Error source:").append(CLASS_NAME + ".createCashFlowOrder()\n").append("Error message:").append(ex.toString() + "\n"));
			this.retErrorInfo.setErrorCode(Global.ERR_CM_EXCEPTION_WHEN_CALL_ONECONNECT);
			this.retErrorInfo.setErrorMessage(ex.toString());
		}
	}

	/**
	 * (TR006)Cancel cash flow transaction
	 * 
	 * Reference: SIBS_044
	 * 
	 * @version 1.0
	 * @author Vu Trung Kien
	 * 
	 */
	private void cancelCashFlowOrder() {
		try {
			// Thieu branch_code???
			String xpathInput = "/message/body/field[@name='%s']";
			String major_acct_no = ElementUtils.getXMLElementInStringValue(inMessage, String.format(xpathInput, "major_acct_no"));
			String major_acct_type = ElementUtils.getXMLElementInStringValue(inMessage, String.format(xpathInput, "major_acct_type"));
			String sub_acct_no = ElementUtils.getXMLElementInStringValue(inMessage, String.format(xpathInput, "sub_acct_no"));
			String sub_acct_type = ElementUtils.getXMLElementInStringValue(inMessage, String.format(xpathInput, "sub_acct_type"));
			String ceiling_amt = CoreBankUtils.roundCBNumberic(ElementUtils.getXMLElementInStringValue(inMessage, String.format(xpathInput, "ceiling_amt")));
			String floor_amt = CoreBankUtils.roundCBNumberic(ElementUtils.getXMLElementInStringValue(inMessage, String.format(xpathInput, "floor_amt")));
			String balance_type = ElementUtils.getXMLElementInStringValue(inMessage, String.format(xpathInput, "balance_type"));
			String fee = ElementUtils.getXMLElementInStringValue(inMessage, String.format(xpathInput, "fee"));

			if (major_acct_no.length() == 0) {
				this.retErrorInfo.setErrorCode(Global.ERR_UDF_SRC_ACCOUNT_NO_NOT_VALID_OR_MISSING);
				this.retErrorInfo.setErrorMessage("ERR_UDF_SRC_ACCOUNT_NO_NOT_VALID_OR_MISSING");
				return;
			}
			if (major_acct_type.length() == 0 || CoreBankUtils.isValidAccountType(major_acct_type) == false) {
				this.retErrorInfo.setErrorCode(Global.ERR_UDF_SRC_ACCOUNT_TYPE_NOT_VALID_OR_MISSING);
				this.retErrorInfo.setErrorMessage("ERR_UDF_SRC_ACCOUNT_TYPE_NOT_VALID_OR_MISSING");
				return;
			}
			if (sub_acct_no.length() == 0) {
				this.retErrorInfo.setErrorCode(Global.ERR_UDF_DES_ACCOUNT_NO_NOT_VALID_OR_MISSING);
				this.retErrorInfo.setErrorMessage("ERR_UDF_DES_ACCOUNT_NO_NOT_VALID_OR_MISSING");
				return;
			}
			if (sub_acct_type.length() == 0 || CoreBankUtils.isValidAccountType(sub_acct_type) == false) {
				this.retErrorInfo.setErrorCode(Global.ERR_UDF_DES_ACCOUNT_TYPE_NOT_VALID_OR_MISSING);
				this.retErrorInfo.setErrorMessage("ERR_UDF_DES_ACCOUNT_TYPE_NOT_VALID_OR_MISSING");
				return;
			}
			rebuildTransactionInfo(SIBS_011, Global.APP_DEFAULT_BRANCH_CODE);
			MBASE_TEMPLATE[47] = "D";// delete
			MBASE_TEMPLATE[48] = "R";// 
			MBASE_TEMPLATE[49] = "1";// numOfRecord
			MBASE_TEMPLATE[50] = "N";// 
			MBASE_TEMPLATE[51] = "F";// 

			MBASE_TEMPLATE[68] = major_acct_no;
			MBASE_TEMPLATE[69] = major_acct_type;
			MBASE_TEMPLATE[70] = sub_acct_no;
			MBASE_TEMPLATE[71] = sub_acct_type;

			MBASE_TEMPLATE[2] = hostMessageLogInfo.getWs_ip();
			MBASE_TEMPLATE[18] = "BBMBSDDMNTFNC";// scenarioNumber
			MBASE_TEMPLATE[25] = hostMessageLogInfo.getTeller_id();
			MBASE_TEMPLATE[26] = hostMessageLogInfo.getWs_name();
			MBASE_TEMPLATE[32] = hostMessageLogInfo.getApprover_id();
			MBASE_TEMPLATE[40] = hostMessageLogInfo.getWs_name();
			MBASE_TEMPLATE[42] = hostMessageLogInfo.getBranch_code();
			MBASE_TEMPLATE[27] = "28131";
			MBASE_TEMPLATE[46] = "28131";

			String hostRequestMessage = AppUtils.convertArrayToString(MBASE_TEMPLATE);
			String hostResponseMessage = "";
			this.hostMessageLogInfo.setSend_time(AppUtils.now(Global.DEF_FORMAT_DATE_TIME_FULL));
			try {
				retMessage = as400Port.hostMessageSending(hostMessageLogInfo.getRef_channel(), hostRequestMessage);
			} catch (RemoteException ex) {
				this.retErrorInfo.setErrorCode(Global.ERR_CM_EXCEPTION_WHEN_CALL_ONECONNECT);
				this.retErrorInfo.setErrorMessage(ex.toString());
			}
			this.hostMessageLogInfo.setReceive_time(AppUtils.now(Global.DEF_FORMAT_DATE_TIME_FULL));
			if (retMessage != null) {
				if (retMessage.getErrCode() == null) {
					String xpathOutput = "/message/?body/?$field[set-value('%s')][?@name[set-value('%s')]]";
					ElementUtils.setXMLElementValue(outMessage, xpathOutput, CoreBankUtils.correctAccountNumber(major_acct_no), "major_acct_no");
					ElementUtils.setXMLElementValue(outMessage, xpathOutput, major_acct_type, "major_acct_type");
					ElementUtils.setXMLElementValue(outMessage, xpathOutput, CoreBankUtils.correctAccountNumber(sub_acct_no), "sub_acct_no");
					ElementUtils.setXMLElementValue(outMessage, xpathOutput, sub_acct_type, "sub_acct_type");
					ElementUtils.setXMLElementValue(outMessage, xpathOutput, ceiling_amt, "ceiling_amt");
					ElementUtils.setXMLElementValue(outMessage, xpathOutput, floor_amt, "floor_amt");
					ElementUtils.setXMLElementValue(outMessage, xpathOutput, balance_type, "balance_type");
					ElementUtils.setXMLElementValue(outMessage, xpathOutput, fee, "fee");
				} else {
					this.retErrorInfo.setErrorCode(Global.ERR_MBASE_START);
					this.retErrorInfo.setErrorMessage(retMessage.getDescription());
					this.retErrorInfo.setErrorType(MESSAGE_TYPE_MBASE);
				}
				hostResponseMessage = AppUtils.convertArrayToString(retMessage.getArrString());
			}

			this.hostMessageLogInfo.setResp_code(String.valueOf(retErrorInfo.getErrorCode()));
			this.hostMessageLogInfo.setResp_msg(retErrorInfo.getErrorMessage());
			this.hostMessageLogInfo.setHostRequestMsg("[" + hostRequestMessage + "]");
			this.hostMessageLogInfo.setHostResponseMsg("[" + hostResponseMessage + "]");
			this.arrRetHOSTMessageLogInfo.add(hostMessageLogInfo);
		} catch (Exception ex) {
			ex.printStackTrace();
			logger.error(new StringBuffer().append("Error source:").append(CLASS_NAME + ".cancelCashFlowOrder()\n").append("Error message:").append(ex.toString() + "\n"));
			this.retErrorInfo.setErrorCode(Global.ERR_CM_EXCEPTION_WHEN_CALL_ONECONNECT);
			this.retErrorInfo.setErrorMessage(ex.toString());
		}
	}

	/**
	 * (CM034)Query CIF inquiryMiniStatement
	 * 
	 * @version 1.0
	 */
	private void inquiryMiniStatement() {
		try {
			String xpathInput = "/message/body/field[@name='%s']";
			String acct_no = ElementUtils.getXMLElementInStringValue(inMessage, String.format(xpathInput, "acct_no"));
			String acct_type = ElementUtils.getXMLElementInStringValue(inMessage, String.format(xpathInput, "acct_type"));
			int startPos = 67;
			int recordLength = 11;

			// this.refTranCode = SIBS_012;
			rebuildTransactionInfo(SIBS_012, Global.APP_DEFAULT_BRANCH_CODE);
			MBASE_TEMPLATE[49] = "10";// numOfRecord
			MBASE_TEMPLATE[68] = acct_no;
			MBASE_TEMPLATE[69] = acct_type;

			MBASE_TEMPLATE[2] = hostMessageLogInfo.getWs_ip();
			MBASE_TEMPLATE[18] = "BBMBSDDINQFNC";// scenarioNumber
			MBASE_TEMPLATE[25] = hostMessageLogInfo.getTeller_id();
			MBASE_TEMPLATE[26] = hostMessageLogInfo.getWs_name();
			MBASE_TEMPLATE[32] = hostMessageLogInfo.getApprover_id();
			MBASE_TEMPLATE[40] = hostMessageLogInfo.getWs_name();
			MBASE_TEMPLATE[42] = hostMessageLogInfo.getBranch_code();
			MBASE_TEMPLATE[27] = "25520";
			MBASE_TEMPLATE[46] = "25520";

			String hostRequestMessage = AppUtils.convertArrayToString(MBASE_TEMPLATE);
			String hostResponseMessage = "";
			this.hostMessageLogInfo.setSend_time(AppUtils.now(Global.DEF_FORMAT_DATE_TIME_FULL));
			try {
				this.retMessage = as400Port.hostMessageSending(hostMessageLogInfo.getRef_channel(), hostRequestMessage);
			} catch (RemoteException e) {
				retErrorInfo.setErrorCode(ERR_CM_EXCEPTION_WHEN_CALL_ONECONNECT);
				retErrorInfo.setErrorMessage(e.getMessage());
			}
			this.hostMessageLogInfo.setReceive_time(AppUtils.now(Global.DEF_FORMAT_DATE_TIME_FULL));
			if (retMessage != null) {
				hostResponseMessage = AppUtils.convertArrayToString(retMessage.getArrString());
				if (retMessage.getErrCode() == null) {
					ArrayList<String[]> retArrResponseRow = AppUtils.getListOfResponseRow(retMessage.getArrString(), startPos, recordLength);
					String xpathOutput = "/message/?body/?list[?@name[set-value('records')]]";
					// 1.Tao the list
					ElementUtils.setXMLElementValue(outMessage, xpathOutput);
					for (int i = 0; i < retArrResponseRow.size(); i++) {
						xpathOutput = "/message/body/list[@name='records']/?$entity[?@name[set-value('" + i + "')]]";
						// 2.Tao tung the entity
						// outMessage.evaluateXPath(xpathOutput);
						ElementUtils.setXMLElementValue(outMessage, xpathOutput);
						// 3.Tao tung the field
						xpathOutput = "/message/body/list[@name='records']/entity[@name='" + i + "']/?$field[set-value('%s')][?@name[set-value('%s')]]";
						ElementUtils.setXMLElementValue(outMessage, xpathOutput, CoreBankUtils.convertCB2EBDate(retArrResponseRow.get(i)[2]), "tran_date");
						ElementUtils.setXMLElementValue(outMessage, xpathOutput, retArrResponseRow.get(i)[8], "tran_code");
						ElementUtils.setXMLElementValue(outMessage, xpathOutput, retArrResponseRow.get(i)[9], "amount");
						ElementUtils.setXMLElementValue(outMessage, xpathOutput, retArrResponseRow.get(i)[10], "tran_type");
					}
				} else {
					this.retErrorInfo.setErrorCode(Global.ERR_MBASE_START);
					this.retErrorInfo.setErrorMessage(retMessage.getDescription());
					this.retErrorInfo.setErrorType(MESSAGE_TYPE_MBASE);
				}
			}
			this.hostMessageLogInfo.setResp_code(String.valueOf(retErrorInfo.getErrorCode()));
			this.hostMessageLogInfo.setResp_msg(retErrorInfo.getErrorMessage());
			this.hostMessageLogInfo.setHostRequestMsg("[" + hostRequestMessage + "]");
			this.hostMessageLogInfo.setHostResponseMsg("[" + hostResponseMessage + "]");
			this.arrRetHOSTMessageLogInfo.add(hostMessageLogInfo);
		} catch (Exception ex) {
			ex.printStackTrace();
			logger.error(new StringBuffer().append("Error source:").append(CLASS_NAME + ".inquiryMiniStatement()\n").append("Error message:").append(ex.toString() + "\n"));
			this.retErrorInfo.setErrorCode(Global.ERR_SYSTEM_UNKNOWN_ERROR);
			this.retErrorInfo.setErrorMessage(ex.toString());
		}
	}

	/**
	 * (OS002)Create FD account
	 * 
	 * Reference: SIBS_032
	 * 
	 * Call : webservice with groupcode (05)
	 * 
	 * Branch code: subbranchcode
	 * 
	 * Currency : 01-VND,37 USD
	 * 
	 * 
	 * @version : 1.0
	 */
	private void createFDAccount() {
		try {
			String xpathInput = "/message/body/field[@name='%s']";
			String cif_no = ElementUtils.getXMLElementInStringValue(inMessage, String.format(xpathInput, "cif_no"));
			// TODO change from fd_branch_no => branch_no
			String fd_branch_no = ElementUtils.getXMLElementInStringValue(inMessage, String.format(xpathInput, "fd_branch_no"));
			String fd_acct_ccy = ElementUtils.getXMLElementInStringValue(inMessage, String.format(xpathInput, "fd_acct_ccy"));

			// thieu account_name???
			if (cif_no.length() == 0) {
				this.retErrorInfo.setErrorCode(Global.ERR_UDF_CIF_NO_NOT_VALID_OR_MISSING);
				this.retErrorInfo.setErrorMessage("ERR_UDF_CIF_NO_NOT_VALID_OR_MISSING");
				return;
			}
			if (fd_acct_ccy.length() == 0) {
				this.retErrorInfo.setErrorCode(Global.ERR_UDF_SRC_CURRENCY_CODE_NOT_VALID_OR_MISSING);
				this.retErrorInfo.setErrorMessage("ERR_UDF_SRC_CURRENCY_CODE_NOT_VALID_OR_MISSING");
				return;
			}
			if (fd_branch_no.length() == 0) {
				this.retErrorInfo.setErrorCode(Global.ERR_UDF_SRC_BRANCH_CODE_NOT_VALID_OR_MISSING);
				this.retErrorInfo.setErrorMessage("ERR_UDF_BRANCH_CODE_NOT_VALID_OR_MISSING");
				return;
			}

			fd_branch_no = CoreBankUtils.correctBranchCode(fd_branch_no);

			// "11000"
			if (fd_branch_no.length() == 3)
				fd_branch_no = fd_branch_no + "00";
			this.hostMessageLogInfo.setSend_time(AppUtils.now(Global.DEF_FORMAT_DATE_TIME_FULL));
			CurrencyInfo currencyInfo = CachedParam.findCurrencyByCode(fd_acct_ccy);
			String currRefCode = currencyInfo.getRefCode();
			String fd_type = currencyInfo.getFd_type();
			String fd_group = currencyInfo.getFd_groupcode();

			String fd_acct_no = as400Port.getAccount(fd_branch_no, "01", "05");
			if (fd_acct_no != null && fd_acct_no.length() > 0) {
				try {
					this.refTranCode = SIBS_013;
					rebuildTransactionInfo(SIBS_013, fd_branch_no);
					this.retMessage = as400Port.createFD(hostMessageLogInfo.getRef_channel(), hostMessageLogInfo.getHost_tran_date(), hostMessageLogInfo.getTeller_id(),
							fd_branch_no, fd_acct_ccy, cif_no, fd_acct_no, "T", "", "Y");
				} catch (RemoteException e) {
					retErrorInfo.setErrorCode(ERR_CM_EXCEPTION_WHEN_CALL_ONECONNECT);
					retErrorInfo.setErrorMessage(e.getMessage());
				}
				if (retMessage != null) {
					if (retMessage.getErrCode() == null) {
						String xmlOuputPattern = "/message/?body/?$field[set-value('%s')][?@name[set-value('%s')]]";
						outMessage.evaluateXPath(String.format(xmlOuputPattern, CoreBankUtils.correctAccountNumber(fd_acct_no), "fd_acct_no"));
						outMessage.evaluateXPath(String.format(xmlOuputPattern, fd_acct_ccy, "fd_acct_ccy"));
						outMessage.evaluateXPath(String.format(xmlOuputPattern, AppUtils.now(Global.DEF_FORMAT_DATE_TIME_FULL), "create_time"));
					}
					this.hostResponseMessage = AppUtils.convertArrayToString(retMessage.getArrString());
				}
			} else {

			}
			this.hostMessageLogInfo.setReceive_time(AppUtils.now(Global.DEF_FORMAT_DATE_TIME_FULL));
			this.hostMessageLogInfo.setResp_code(String.valueOf(retErrorInfo.getErrorCode()));
			this.hostMessageLogInfo.setResp_msg(retErrorInfo.getErrorMessage());
			this.hostMessageLogInfo.setHostRequestMsg("[channel:" + hostMessageLogInfo.getRef_channel() + "," + "tran_date:" + hostMessageLogInfo.getHost_tran_date() + ","
					+ "tellerid:" + hostMessageLogInfo.getTeller_id() + "," + "branch_no:" + fd_branch_no + "," + "fd_acct_ccy:" + fd_acct_ccy + "," + "cif_no:" + cif_no + ","
					+ "fd_acct_no:" + fd_acct_no + ",:" + "T" + "," + "," + "Y" + "]");
			this.hostMessageLogInfo.setHostResponseMsg("[" + hostResponseMessage + "]");
			this.arrRetHOSTMessageLogInfo.add(hostMessageLogInfo);
		} catch (Exception ex) {
			ex.printStackTrace();
			logger.error(new StringBuffer().append("Error source:").append(CLASS_NAME + ".createFDAccount()\n").append("Error message:").append(ex.toString() + "\n"));
			this.retErrorInfo.setErrorCode(Global.ERR_CM_EXCEPTION_WHEN_CALL_ONECONNECT);
			this.retErrorInfo.setErrorMessage(ex.toString());
		}
	}

	/**
	 * (OS003)Create FD receipt
	 * 
	 * Reference: SIBS_031
	 * 
	 * Call : webservice with groupcode (1)
	 * 
	 * @version : 1.0
	 */
	private void createFDReceipt() {
		try {
			String xpathInput = "/message/body/field[@name='%s']";
			String fd_branch_no = ElementUtils.getXMLElementInStringValue(inMessage, String.format(xpathInput, "fd_branch_no"));
			String fd_acct_no = ElementUtils.getXMLElementInStringValue(inMessage, String.format(xpathInput, "fd_acct_no"));
			String fd_acct_ccy = ElementUtils.getXMLElementInStringValue(inMessage, String.format(xpathInput, "fd_acct_ccy"));
			String fd_product_code = ElementUtils.getXMLElementInStringValue(inMessage, String.format(xpathInput, "fd_product_code"));
			String is_rollout_interest = ElementUtils.getXMLElementInStringValue(inMessage, String.format(xpathInput, "is_rollout_interest"));
			String interest_receive_acct = ElementUtils.getXMLElementInStringValue(inMessage, String.format(xpathInput, "interest_receive_acct"));
			String deposit_amt = CoreBankUtils.roundCBNumberic(ElementUtils.getXMLElementInStringValue(inMessage, String.format(xpathInput, "amt")));
			String effective_date = ElementUtils.getXMLElementInStringValue(inMessage, String.format(xpathInput, "effective_date"));
			String remark = AppUtils.convertToVietnamesNoSign(ElementUtils.getXMLElementInStringValue(inMessage, String.format(xpathInput, "remark")));
			String principle_receive_acct = ElementUtils.getXMLElementInStringValue(inMessage, String.format(xpathInput, "principle_receive_acct"));

			if (fd_branch_no.length() == 0) {
				this.retErrorInfo.setErrorCode(Global.ERR_UDF_SRC_BRANCH_CODE_NOT_VALID_OR_MISSING);
				this.retErrorInfo.setErrorMessage("ERR_UDF_SRC_BRANCH_CODE_NOT_VALID_OR_MISSING");
				return;
			}
			if (fd_acct_no.length() == 0) {
				this.retErrorInfo.setErrorCode(Global.ERR_UDF_SRC_ACCOUNT_NO_NOT_VALID_OR_MISSING);
				this.retErrorInfo.setErrorMessage("ERR_UDF_SRC_ACCOUNT_NO_NOT_VALID_OR_MISSING");
				return;
			}
			if (fd_acct_ccy.length() == 0) {
				this.retErrorInfo.setErrorCode(Global.ERR_UDF_SRC_CURRENCY_CODE_NOT_VALID_OR_MISSING);
				this.retErrorInfo.setErrorMessage("ERR_UDF_SRC_CURRENCY_CODE_NOT_VALID_OR_MISSING");
				return;
			}
			if (fd_product_code.length() == 0) {
				this.retErrorInfo.setErrorCode(Global.ERR_UDF_FDPRODUCT_NOT_VALID_OR_MISSING);
				this.retErrorInfo.setErrorMessage("ERR_UDF_FDPRODUCT_NOT_VALID_OR_MISSING");
				return;
			}
			if (!CoreBankUtils.isValidTransactionAmount(deposit_amt)) {
				this.retErrorInfo.setErrorCode(Global.ERR_UDF_TRANSACTION_AMOUNT_NOT_VALID_OR_MISSING);
				this.retErrorInfo.setErrorMessage("ERR_UDF_TRANSACTION_AMOUT_NOT_VALID_OR_MISSING");
				return;
			}

			// Correct lai du lieu truoc khi thuc hien
			fd_branch_no = CoreBankUtils.correctBranchCode(fd_branch_no);
			deposit_amt = CoreBankUtils.convertEB2CBNumeric(deposit_amt);
			effective_date = hostMessageLogInfo.getHost_tran_date();

			if (fd_branch_no.length() < 5)
				fd_branch_no += "00";

			CurrencyInfo currencyInfo = CachedParam.findCurrencyByCode(fd_acct_ccy);
			String currRefCode = currencyInfo.getRefCode();
			String fd_type = currencyInfo.getFd_type();
			String fd_group = currencyInfo.getFd_groupcode();

			// Production groupcode="2" =>khong cap so
			this.hostMessageLogInfo.setSend_time(AppUtils.now(Global.DEF_FORMAT_DATE_TIME_FULL));
			String receipt_no = as400Port.getFDReceiptAccount(fd_branch_no, currRefCode, fd_group);// "1");

			if (receipt_no != null) {
				this.hostMessageLogInfo.setSend_time(AppUtils.now(Global.DEF_FORMAT_DATE_TIME_FULL));
				try {
					String intPaymentMode = "D";
					String fdType = fd_type;// "2";
					String autoRenew = "Y";
					String rate = "0000000000";
					rebuildTransactionInfo(SIBS_014, fd_branch_no);
					retMessage = as400Port.createFDReceipt(this.hostMessageLogInfo.getRef_channel(), hostMessageLogInfo.getTeller_id(), fd_branch_no, hostMessageLogInfo
							.getHost_tran_sn(), hostMessageLogInfo.getHost_tran_date(), fd_acct_no, deposit_amt, effective_date, receipt_no, rate, interest_receive_acct,
							principle_receive_acct, fd_acct_ccy, fd_product_code, autoRenew, intPaymentMode, fdType, remark);
				} catch (RemoteException e) {
					retErrorInfo.setErrorCode(ERR_CM_EXCEPTION_WHEN_CALL_ONECONNECT);
					retErrorInfo.setErrorMessage(e.getMessage());
				}
				this.hostMessageLogInfo.setReceive_time(AppUtils.now(Global.DEF_FORMAT_DATE_TIME_FULL));

				if (retMessage != null) {
					this.hostResponseMessage = AppUtils.convertArrayToString(retMessage.getArrString());
					if (retMessage.getErrCode() == null) {
						String xpathOutput = "/message/?body/?$field[set-value('%s')][?@name[set-value('%s')]]";
						outMessage.evaluateXPath(String.format(xpathOutput, CoreBankUtils.correctAccountNumber(fd_acct_no), "fd_acct_no"));
						outMessage.evaluateXPath(String.format(xpathOutput, CoreBankUtils.correctAccountNumber(receipt_no), "receipt_no"));
						outMessage.evaluateXPath(String.format(xpathOutput, AppUtils.now(Global.DEF_FORMAT_DATE_TIME_FULL), "create_time"));
					} else {
						retErrorInfo = CachedParam.mappingErrorCode(retMessage.getErrCode(), retMessage.getDescription(), MESSAGE_TYPE_ABCS);
					}
				}
			}
			this.hostMessageLogInfo.setReceive_time(AppUtils.now(Global.DEF_FORMAT_DATE_TIME_FULL));
			this.hostMessageLogInfo.setResp_code(String.valueOf(retErrorInfo.getErrorCode()));
			this.hostMessageLogInfo.setResp_msg(retErrorInfo.getErrorMessage());
			this.hostMessageLogInfo.setHostRequestMsg("[fd_acct_no:" + fd_acct_no + ", deposit_amt:" + deposit_amt + ", effective_date:" + effective_date + ", receipt_no:"
					+ receipt_no + ", interest_receive_acct:" + interest_receive_acct + ", fd_acct_ccy:" + fd_acct_ccy + ", fd_product_code:" + fd_product_code + "]");
			this.hostMessageLogInfo.setHostResponseMsg("[" + hostResponseMessage + "]");
			this.arrRetHOSTMessageLogInfo.add((HOSTMessagLogInfo) hostMessageLogInfo.clone());

		} catch (Exception ex) {
			ex.printStackTrace();
			logger.error(new StringBuffer().append("Error source:").append(CLASS_NAME + ".createFDReceipt()\n").append("Error message:").append(ex.toString() + "\n"));
			this.retErrorInfo.setErrorCode(Global.ERR_CM_EXCEPTION_WHEN_CALL_ONECONNECT);
			this.retErrorInfo.setErrorMessage(ex.toString());
		}
	}

	/**
	 * (CS002)Active ATM card
	 * 
	 * Reference: SIBS_071
	 * 
	 * @version 1.0
	 */
	private void activeATMCard() {
		try {
			String xpathInput = "/message/body/field[@name='%s']";
			String cif_no = ElementUtils.getXMLElementInStringValue(inMessage, String.format(xpathInput, "cif_no"));
			String card_no = ElementUtils.getXMLElementInStringValue(inMessage, String.format(xpathInput, "card_no"));
			String cert_code = ElementUtils.getXMLElementInStringValue(inMessage, String.format(xpathInput, "cert_code"));
			String cert_type = ElementUtils.getXMLElementInStringValue(inMessage, String.format(xpathInput, "cert_type"));

			if (cif_no.length() == 0) {
				this.retErrorInfo.setErrorCode(Global.ERR_UDF_CIF_NO_NOT_VALID_OR_MISSING);
				this.retErrorInfo.setErrorMessage("ERR_UDF_CIF_NO_NOT_VALID_OR_MISSING");
				return;
			}
			if (card_no.length() == 0) {
				this.retErrorInfo.setErrorCode(Global.ERR_UDF_CARD_NO_NOT_VALID_OR_MISSING);
				this.retErrorInfo.setErrorMessage("ERR_UDF_CARD_NO_NOT_VALID_OR_MISSING");
				return;
			}
			if (cert_code.length() == 0) {
				this.retErrorInfo.setErrorCode(Global.ERR_UDF_CERT_CODE_NOT_VALID_OR_MISSING);
				this.retErrorInfo.setErrorMessage("ERR_UDF_CERT_CODE_NOT_VALID_OR_MISSING");
				return;
			}
			if (cert_type.length() == 0) {
				this.retErrorInfo.setErrorCode(Global.ERR_UDF_CERT_TYPE_NOT_VALID_OR_MISSING);
				this.retErrorInfo.setErrorMessage("ERR_UDF_CERT_TYPE_NOT_VALID_OR_MISSING");
				return;
			}

			this.hostMessageLogInfo.setSend_time(AppUtils.now(Global.DEF_FORMAT_DATE_TIME_FULL));
			try {
				rebuildTransactionInfo(SIBS_015, Global.APP_DEFAULT_BRANCH_CODE);
				this.retMessage = as400Port.cardActivation(hostMessageLogInfo.getRef_channel(), hostMessageLogInfo.getTeller_id(), hostMessageLogInfo.getBranch_code(), card_no,
						cif_no, cert_code, cert_type);

			} catch (RemoteException e) {
				retErrorInfo.setErrorCode(ERR_CM_EXCEPTION_WHEN_CALL_ONECONNECT);
				retErrorInfo.setErrorMessage(e.getMessage());
			}
			this.hostMessageLogInfo.setReceive_time(AppUtils.now(Global.DEF_FORMAT_DATE_TIME_FULL));

			if (retMessage != null) {
				this.hostResponseMessage = AppUtils.convertArrayToString(retMessage.getArrString());
				if (retMessage.getErrCode() == null) {
					this.retErrorInfo.setErrorCode(ERR_SYSTEM_OK);
					this.retErrorInfo.setErrorMessage(retMessage.getDescription());
				} else {
					this.retErrorInfo.setErrorCode(Global.ERR_MBASE_START);
					this.retErrorInfo.setErrorMessage(retMessage.getDescription());
				}
			}
			this.hostMessageLogInfo.setResp_code(String.valueOf(retErrorInfo.getErrorCode()));
			this.hostMessageLogInfo.setResp_msg(retErrorInfo.getErrorMessage());
			this.hostMessageLogInfo.setHostRequestMsg("[cif_no:" + cif_no + ", card_no:" + card_no + ", cert_code:" + cert_code + ", cert_type:" + cert_type + "]");
			this.hostMessageLogInfo.setHostResponseMsg("[" + hostResponseMessage + "]");
			this.arrRetHOSTMessageLogInfo.add((HOSTMessagLogInfo) hostMessageLogInfo.clone());

		} catch (Exception ex) {
			ex.printStackTrace();
			logger.error(new StringBuffer().append("Error source:").append(CLASS_NAME + ".activeATMCard()\n").append("Error message:").append(ex.toString() + "\n"));
			this.retErrorInfo.setErrorCode(Global.ERR_CM_EXCEPTION_WHEN_CALL_ONECONNECT);
			this.retErrorInfo.setErrorMessage(ex.toString());
		}
	}

	/**
	 * (LN002)Loan payment online
	 * 
	 * @version 1.0
	 * @author Vu Trung Kien
	 */
	private void loanPayment() {
		try {

			String xpathInput = "/message/body/field[@name='%s']";
			String is_payment_adv = ElementUtils.getXMLElementInStringValue(inMessage, String.format(xpathInput, "is_payment_adv"));
			String is_payoff_tran = ElementUtils.getXMLElementInStringValue(inMessage, String.format(xpathInput, "is_payoff_tran"));
			String rollout_branch_no = ElementUtils.getXMLElementInStringValue(inMessage, String.format(xpathInput, "rollout_branch_no"));
			String rollout_acct_no = ElementUtils.getXMLElementInStringValue(inMessage, String.format(xpathInput, "rollout_acct_no"));
			String rollout_acct_ccy = ElementUtils.getXMLElementInStringValue(inMessage, String.format(xpathInput, "rollout_acct_ccy"));
			String rollout_buy_rate = ElementUtils.getXMLElementInStringValue(inMessage, String.format(xpathInput, "rollout_buy_rate"));
			String loan_branch_no = ElementUtils.getXMLElementInStringValue(inMessage, String.format(xpathInput, "loan_branch_no"));
			String loan_acct_no = ElementUtils.getXMLElementInStringValue(inMessage, String.format(xpathInput, "loan_acct_no"));
			String loan_acct_ccy = ElementUtils.getXMLElementInStringValue(inMessage, String.format(xpathInput, "loan_acct_ccy"));
			String loan_sell_rate = ElementUtils.getXMLElementInStringValue(inMessage, String.format(xpathInput, "loan_sell_rate"));
			String effective_date = ElementUtils.getXMLElementInStringValue(inMessage, String.format(xpathInput, "effective_date"));
			String cr_amt = CoreBankUtils.roundCBNumberic(ElementUtils.getXMLElementInStringValue(inMessage, String.format(xpathInput, "cr_amt")));
			String billed_interest = ElementUtils.getXMLElementInStringValue(inMessage, String.format(xpathInput, "billed_interest"));
			String billed_late_charge = ElementUtils.getXMLElementInStringValue(inMessage, String.format(xpathInput, "billed_late_charge"));
			String billed_principal = ElementUtils.getXMLElementInStringValue(inMessage, String.format(xpathInput, "billed_principal"));
			String final_payment_amt = ElementUtils.getXMLElementInStringValue(inMessage, String.format(xpathInput, "final_payment_amt"));
			String fee = CoreBankUtils.roundCBNumberic(ElementUtils.getXMLElementInStringValue(inMessage, String.format(xpathInput, "fee")));
			String remark = AppUtils.convertToVietnamesNoSign(ElementUtils.getXMLElementInStringValue(inMessage, String.format(xpathInput, "remark")));

			if (rollout_branch_no.length() == 0) {
				this.retErrorInfo.setErrorCode(Global.ERR_UDF_SRC_BRANCH_CODE_NOT_VALID_OR_MISSING);
				this.retErrorInfo.setErrorMessage("ERR_UDF_SRC_BRANCH_CODE_NOT_VALID_OR_MISSING");
				return;
			}
			if (rollout_acct_no.length() == 0) {
				this.retErrorInfo.setErrorCode(Global.ERR_UDF_SRC_ACCOUNT_NO_NOT_VALID_OR_MISSING);
				this.retErrorInfo.setErrorMessage("ERR_UDF_SRC_ACCOUNT_NO_NOT_VALID_OR_MISSING");
				return;
			}
			if (rollout_acct_ccy.length() == 0) {
				this.retErrorInfo.setErrorCode(Global.ERR_UDF_SRC_CURRENCY_CODE_NOT_VALID_OR_MISSING);
				this.retErrorInfo.setErrorMessage("ERR_UDF_SRC_CURRENCY_CODE_NOT_VALID_OR_MISSING");
				return;
			}
			if (rollout_buy_rate.length() == 0) {
				this.retErrorInfo.setErrorCode(Global.ERR_UDF_SELL_RATE_NOT_VALID_OR_MISSING);
				this.retErrorInfo.setErrorMessage("ERR_UDF_SELL_RATE_AMOUT_NOT_VALID_OR_MISSING");
				return;
			}

			if (loan_branch_no.length() == 0) {
				this.retErrorInfo.setErrorCode(Global.ERR_UDF_DES_BRANCH_CODE_NOT_VALID_OR_MISSING);
				this.retErrorInfo.setErrorMessage("ERR_UDF_SRC_BRANCH_CODE_NOT_VALID_OR_MISSING");
				return;
			}
			if (loan_acct_no.length() == 0) {
				this.retErrorInfo.setErrorCode(Global.ERR_UDF_DES_BRANCH_CODE_NOT_VALID_OR_MISSING);
				this.retErrorInfo.setErrorMessage("ERR_UDF_SRC_BRANCH_CODE_NOT_VALID_OR_MISSING");
				return;
			}

			if (loan_acct_ccy.length() == 0) {
				this.retErrorInfo.setErrorCode(Global.ERR_UDF_DES_CURRENCY_CODE_NOT_VALID_OR_MISSING);
				this.retErrorInfo.setErrorMessage("ERR_UDF_DES_CURRENCY_CODE_NOT_VALID_OR_MISSING");
				return;
			}
			if (loan_sell_rate.length() == 0) {
				this.retErrorInfo.setErrorCode(Global.ERR_UDF_BUY_RATE_NOT_VALID_OR_MISSING);
				this.retErrorInfo.setErrorMessage("ERR_UDF_BUY_RATE_NOT_VALID_OR_MISSING");
				return;
			}
			if (!CoreBankUtils.isValidTransactionAmount(cr_amt)) {
				this.retErrorInfo.setErrorCode(Global.ERR_UDF_TRANSACTION_AMOUNT_NOT_VALID_OR_MISSING);
				this.retErrorInfo.setErrorMessage("ERR_UDF_TRANSACTION_AMOUT_NOT_VALID_OR_MISSING");
				return;
			}

			if (is_payment_adv.equals("Y")) {// advance 4245
				ABCS_TEMPLATE[0] = "";
				ABCS_TEMPLATE[0] = "";
				ABCS_TEMPLATE[0] = "";
				ABCS_TEMPLATE[0] = "";
				ABCS_TEMPLATE[0] = "";
				ABCS_TEMPLATE[0] = "";
				ABCS_TEMPLATE[0] = "";
				ABCS_TEMPLATE[0] = "";
				ABCS_TEMPLATE[0] = "";
				rebuildTransactionInfo(SIBS_023, rollout_branch_no);
			}
			if (is_payoff_tran.equals("Y")) {// payoff 4920
				ABCS_TEMPLATE[0] = "";
				ABCS_TEMPLATE[0] = "";
				ABCS_TEMPLATE[0] = "";
				ABCS_TEMPLATE[0] = "";
				ABCS_TEMPLATE[0] = "";
				ABCS_TEMPLATE[0] = "";
				ABCS_TEMPLATE[0] = "";
				ABCS_TEMPLATE[0] = "";
				ABCS_TEMPLATE[0] = "";
				rebuildTransactionInfo(SIBS_024, rollout_branch_no);
			}

			String hostRequestMessage = "";
			String hostResponseMessage = "";

			hostRequestMessage = AppUtils.convertArrayToString(ABCS_TEMPLATE);

			this.hostMessageLogInfo.setSend_time(AppUtils.now(Global.DEF_FORMAT_DATE_TIME_FULL));
			this.retMessage = as400Port.hostMessageSending(hostMessageLogInfo.getRef_channel(), hostRequestMessage);
			this.hostMessageLogInfo.setReceive_time(AppUtils.now(Global.DEF_FORMAT_DATE_TIME_FULL));

			if (this.retMessage != null) {
				if (this.retMessage.getErrCode() == null) {
				} else {
				}
				hostResponseMessage = AppUtils.convertArrayToString(retMessage.getArrString());
			}

			this.hostMessageLogInfo.setResp_code(String.valueOf(retErrorInfo.getErrorCode()));
			this.hostMessageLogInfo.setResp_msg(retErrorInfo.getErrorMessage());
			this.hostMessageLogInfo.setHostRequestMsg(hostRequestMessage);
			this.hostMessageLogInfo.setHostResponseMsg(hostResponseMessage);
			this.arrRetHOSTMessageLogInfo.add(hostMessageLogInfo);

		} catch (Exception ex) {
			ex.printStackTrace();
			logger.error(new StringBuffer().append("Error source:").append(CLASS_NAME + ".loanPayment()\n").append("Error message:").append(ex.toString() + "\n"));
			this.retErrorInfo.setErrorCode(Global.ERR_SYSTEM_UNKNOWN_ERROR);
			this.retErrorInfo.setErrorMessage(ex.toString());
		}
	}

	/**
	 * (TR003)Transfer money
	 * 
	 * Reference : SIBS_011 (CA->CA),SIBS_021 (SA->SA)
	 * 
	 * @version 1.0
	 */
	private void fundTransfer() {
		try {
			// CSP200: Salary Payment Transaction CTR203: retail batch transfer:
			// RTR004: corporate batch transfer
			String xmlInputPattern = "/message/body/entity[@name='summary']/field[@name='%s']";
			String cif_no = ElementUtils.getXMLElementInStringValue(inMessage, String.format(xmlInputPattern, "cif_no"));
			String cif_acct_name = ElementUtils.getXMLElementInStringValue(inMessage, String.format(xmlInputPattern, "cif_acct_name"));
			String cert_type = ElementUtils.getXMLElementInStringValue(inMessage, String.format(xmlInputPattern, "cert_type"));
			String cert_code = ElementUtils.getXMLElementInStringValue(inMessage, String.format(xmlInputPattern, "cert_code"));
			String issue_date = ElementUtils.getXMLElementInStringValue(inMessage, String.format(xmlInputPattern, "issue_date"));
			String issue_place = ElementUtils.getXMLElementInStringValue(inMessage, String.format(xmlInputPattern, "issue_place"));

			String is_batches = ElementUtils.getXMLElementInStringValue(inMessage, String.format(xmlInputPattern, "is_batches"));
			String batch_no = ElementUtils.getXMLElementInStringValue(inMessage, String.format(xmlInputPattern, "batch_no"));
			String batch_records = ElementUtils.getXMLElementInStringValue(inMessage, String.format(xmlInputPattern, "batch_records"));

			String msg_seq_no = ElementUtils.getXMLElementInStringValue(inMessage, String.format(xmlInputPattern, "msg_seq_no"));
			String msg_records = ElementUtils.getXMLElementInStringValue(inMessage, String.format(xmlInputPattern, "msg_records"));
			String is_schedule = ElementUtils.getXMLElementInStringValue(inMessage, String.format(xmlInputPattern, "is_schedule"));

			String validated_date = ElementUtils.getXMLElementInStringValue(inMessage, String.format(xmlInputPattern, "validated_date"));
			String epd_date = ElementUtils.getXMLElementInStringValue(inMessage, String.format(xmlInputPattern, "epd_date"));
			String frq_type = ElementUtils.getXMLElementInStringValue(inMessage, String.format(xmlInputPattern, "frq_type"));

			String frq = ElementUtils.getXMLElementInStringValue(inMessage, String.format(xmlInputPattern, "frq"));
			String frq_limit = ElementUtils.getXMLElementInStringValue(inMessage, String.format(xmlInputPattern, "frq_limit"));
			String is_lack_stop = ElementUtils.getXMLElementInStringValue(inMessage, String.format(xmlInputPattern, "is_lack_stop"));
			String debit_date = ElementUtils.getXMLElementInStringValue(inMessage, String.format(xmlInputPattern, "debit_date"));
			String debit_time = ElementUtils.getXMLElementInStringValue(inMessage, String.format(xmlInputPattern, "debit_time"));

			int iTotalRecord = 0;
			int iSuccesfulRecord = 0;
			ErrorInfo lastRetErrorInfo = new ErrorInfo(ERR_SYSTEM_OK, ERR_SYSTEM_OK_MSG, MESSAGE_TYPE_ABCS);
			List<MbElement> listOfTransfer = ElementUtils.getListOfXMLElement(inMessage, "/message/body/list[@name='records']/entity");
			String xmlInputPattern_2 = "/message/?body/?list[?@name[set-value('records')]]";
			outMessage.evaluateXPath(xmlInputPattern_2);
			String GLAccount = "";
			for (int i = 0; i < listOfTransfer.size(); i++) {
				// 2.Tao tung the entity
				xmlInputPattern_2 = "/message/body/list[@name='records']/?$entity[?@name[set-value('" + i + "')]]";
				outMessage.evaluateXPath(xmlInputPattern_2);

				// 3.Process detail
				ErrorInfo tempErrorInfo = new ErrorInfo(ERR_SYSTEM_OK, ERR_SYSTEM_OK_MSG, MESSAGE_TYPE_ABCS);
				xmlInputPattern_2 = "/message/body/list[@name='records']/entity[@name='" + (i) + "']/field[@name='%s']";

				String tran_sn = ElementUtils.getXMLElementInStringValue(inMessage, String.format(xmlInputPattern_2, "tran_sn"));
				String product_code = ElementUtils.getXMLElementInStringValue(inMessage, String.format(xmlInputPattern_2, "product_code"));
				String is_outward_transfer = ElementUtils.getXMLElementInStringValue(inMessage, String.format(xmlInputPattern_2, "is_outward_transfer"));
				String rollout_branch_no = ElementUtils.getXMLElementInStringValue(inMessage, String.format(xmlInputPattern_2, "rollout_branch_no"));
				String bnfc_branch_no = ElementUtils.getXMLElementInStringValue(inMessage, String.format(xmlInputPattern_2, "bnfc_branch_no"));
				String rollout_acct_no = ElementUtils.getXMLElementInStringValue(inMessage, String.format(xmlInputPattern_2, "rollout_acct_no"));
				String rollout_acct_name = AppUtils.convertToVietnamesNoSign(ElementUtils.getXMLElementInStringValue(inMessage, String.format(xmlInputPattern_2,
						"rollout_acct_name")));
				String rollout_acct_type = ElementUtils.getXMLElementInStringValue(inMessage, String.format(xmlInputPattern_2, "rollout_acct_type"));
				String rollout_acct_ccy = ElementUtils.getXMLElementInStringValue(inMessage, String.format(xmlInputPattern_2, "rollout_acct_ccy"));
				String rollout_buy_rate = ElementUtils.getXMLElementInStringValue(inMessage, String.format(xmlInputPattern_2, "rollout_buy_rate"));

				String bnfc_acct_no = ElementUtils.getXMLElementInStringValue(inMessage, String.format(xmlInputPattern_2, "bnfc_acct_no"));
				String bnfc_acct_name = AppUtils.convertToVietnamesNoSign(ElementUtils.getXMLElementInStringValue(inMessage, String.format(xmlInputPattern_2, "bnfc_name")));
				String bnfc_acct_type = ElementUtils.getXMLElementInStringValue(inMessage, String.format(xmlInputPattern_2, "bnfc_acct_type"));
				String bnfc_acct_ccy = ElementUtils.getXMLElementInStringValue(inMessage, String.format(xmlInputPattern_2, "bnfc_acct_ccy"));
				String bnfc_sell_rate = ElementUtils.getXMLElementInStringValue(inMessage, String.format(xmlInputPattern_2, "bnfc_sell_rate"));

				String bnfc_bank_id = ElementUtils.getXMLElementInStringValue(inMessage, String.format(xmlInputPattern_2, "bnfc_bank_id"));
				String bnfc_bank_name = AppUtils.convertToVietnamesNoSign(ElementUtils.getXMLElementInStringValue(inMessage, String.format(xmlInputPattern_2, "bnfc_bank_name")));
				String bnfc_bank_addr = AppUtils.convertToVietnamesNoSign(ElementUtils.getXMLElementInStringValue(inMessage, String.format(xmlInputPattern_2, "bnfc_bank_addr")));
				String bnfc_branch_id = ElementUtils.getXMLElementInStringValue(inMessage, String.format(xmlInputPattern_2, "bnfc_branch_id"));
				String bnfc_branch_name = AppUtils.convertToVietnamesNoSign(ElementUtils
						.getXMLElementInStringValue(inMessage, String.format(xmlInputPattern_2, "bnfc_branch_name")));
				String amt = CoreBankUtils.roundCBNumberic(ElementUtils.getXMLElementInStringValue(inMessage, String.format(xmlInputPattern_2, "amt")));
				String fee = CoreBankUtils.roundCBNumberic(ElementUtils.getXMLElementInStringValue(inMessage, String.format(xmlInputPattern_2, "fee")));
				String remark = AppUtils.convertToVietnamesNoSign(ElementUtils.getXMLElementInStringValue(inMessage, String.format(xmlInputPattern_2, "remark")));

				if (is_outward_transfer.length() == 0) {
					tempErrorInfo.setErrorCode(Global.ERR_UDF_TRANSFER_TYPE_NOT_VALID_OR_MISSING);
					tempErrorInfo.setErrorMessage("ERR_UDF_TRANSFER_TYPE_NOT_VALID_OR_MISSING");

				}
				if (is_batches.length() == 0) {
					tempErrorInfo.setErrorCode(Global.ERR_UDF_IS_BATCH_TRAN_NOT_VALID_OR_MISSING);
					tempErrorInfo.setErrorMessage("ERR_UDF_IS_BATCH_TRAN_NOT_VALID_OR_MISSING");

				}
				if (tran_sn.length() == 0) {
					tempErrorInfo.setErrorCode(Global.ERR_UDF_TRAN_SN_NOT_VALID_OR_MISSING);
					tempErrorInfo.setErrorMessage("ERR_UDF_TRAN_SN_NOT_VALID_OR_MISSING");

				}

				if (rollout_branch_no.length() == 0) {
					tempErrorInfo.setErrorCode(Global.ERR_UDF_SRC_BRANCH_CODE_NOT_VALID_OR_MISSING);
					tempErrorInfo.setErrorMessage("ERR_UDF_SRC_BRANCH_CODE_NOT_VALID_OR_MISSING");

				}
				if (rollout_acct_no.length() == 0) {
					tempErrorInfo.setErrorCode(Global.ERR_UDF_SRC_ACCOUNT_NO_NOT_VALID_OR_MISSING);
					tempErrorInfo.setErrorMessage("ERR_UDF_SRC_ACCOUNT_NO_NOT_VALID_OR_MISSING");

				}
				if (rollout_acct_ccy.length() == 0) {
					tempErrorInfo.setErrorCode(Global.ERR_UDF_SRC_CURRENCY_CODE_NOT_VALID_OR_MISSING);
					tempErrorInfo.setErrorMessage("ERR_UDF_SRC_CURRENCY_CODE_NOT_VALID_OR_MISSING");

				}

				if (rollout_buy_rate.length() == 0) {
					tempErrorInfo.setErrorCode(Global.ERR_UDF_SELL_RATE_NOT_VALID_OR_MISSING);
					tempErrorInfo.setErrorMessage("ERR_UDF_SELL_RATE_AMOUT_NOT_VALID_OR_MISSING");

				}
				if (rollout_acct_type.length() == 0 || CoreBankUtils.isValidAccountType(rollout_acct_type) == false) {
					tempErrorInfo.setErrorCode(Global.ERR_UDF_SRC_ACCOUNT_TYPE_NOT_VALID_OR_MISSING);
					tempErrorInfo.setErrorMessage("ERR_UDF_SRC_ACCOUNT_TYPE_NOT_VALID_OR_MISSING");

				}

				if (!CoreBankUtils.isValidTransactionAmount(amt)) {
					tempErrorInfo.setErrorCode(Global.ERR_UDF_TRANSACTION_AMOUNT_NOT_VALID_OR_MISSING);
					tempErrorInfo.setErrorMessage("ERR_UDF_TRANSACTION_AMOUT_NOT_VALID_OR_MISSING");

				}

				String hostRequestMessage = "";
				String hostResponseMessage = "";

				// TODO : need remove 2 rows below
				bnfc_sell_rate = rollout_buy_rate;
				bnfc_acct_ccy = rollout_acct_ccy;
				bnfc_acct_type = rollout_acct_type;
				if (bnfc_branch_no.length() == 0) {
					bnfc_branch_no = bnfc_acct_no.substring(0, 3);
				}
				// End TODO

				if (tempErrorInfo.getErrorCode() == ERR_SYSTEM_OK) {
					if (is_outward_transfer.equals("N")) {// internal-bank
						if (bnfc_branch_no.length() == 0) {
							tempErrorInfo.setErrorCode(Global.ERR_UDF_DES_BRANCH_CODE_NOT_VALID_OR_MISSING);
							tempErrorInfo.setErrorMessage("ERR_UDF_SRC_BRANCH_CODE_NOT_VALID_OR_MISSING");
						}
						if (bnfc_acct_no.length() == 0) {
							tempErrorInfo.setErrorCode(Global.ERR_UDF_DES_ACCOUNT_NO_NOT_VALID_OR_MISSING);
							tempErrorInfo.setErrorMessage("ERR_UDF_SRC_BRANCH_CODE_NOT_VALID_OR_MISSING");

						}

						// TODO :temporary
						if (bnfc_acct_type.length() == 0 || CoreBankUtils.isValidAccountType(bnfc_acct_type) == false) {
							tempErrorInfo.setErrorCode(Global.ERR_UDF_DES_ACCOUNT_TYPE_NOT_VALID_OR_MISSING);
							tempErrorInfo.setErrorMessage("ERR_UDF_DES_ACCOUNT_TYPE_NOT_VALID_OR_MISSING");

						}
						if (bnfc_acct_ccy.length() == 0) {
							tempErrorInfo.setErrorCode(Global.ERR_UDF_DES_CURRENCY_CODE_NOT_VALID_OR_MISSING);
							tempErrorInfo.setErrorMessage("ERR_UDF_DES_CURRENCY_CODE_NOT_VALID_OR_MISSING");

						}
						if (bnfc_sell_rate.length() == 0) {
							tempErrorInfo.setErrorCode(Global.ERR_UDF_BUY_RATE_NOT_VALID_OR_MISSING);
							tempErrorInfo.setErrorMessage("ERR_UDF_BUY_RATE_NOT_VALID_OR_MISSING");

						}
						if (rollout_acct_type.equals(Global.COREBBANK_CA_ACCOUNT_TYPE)) {
							if (bnfc_branch_no.equals(rollout_branch_no)) {
								this.refTranCode = SIBS_018;
							} else {
								this.refTranCode = SIBS_019;
							}
						} else if (rollout_acct_type.equals(Global.COREBBANK_SA_ACCOUNT_TYPE)) {
							if (bnfc_branch_no.equals(rollout_branch_no)) {
								this.refTranCode = SIBS_020;
							} else {
								this.refTranCode = SIBS_021;
							}
						}
						// Chi lam neu du lieu da duoc valid het
						if (tempErrorInfo.getErrorCode() == ERR_SYSTEM_OK) {
							String vatFee = "0";
							// TODO
							rebuildTransactionInfo(this.refTranCode, rollout_branch_no);
							this.hostMessageLogInfo.setSend_time(AppUtils.now(Global.DEF_FORMAT_DATE_TIME_FULL));
							try {
								this.retMessage = as400Port.transferFromCASAToCASA(hostMessageLogInfo.getRef_channel(), rollout_branch_no, bnfc_acct_no, amt, bnfc_acct_ccy,
										bnfc_sell_rate, rollout_acct_no, amt, rollout_acct_ccy, rollout_buy_rate, hostMessageLogInfo.getApprover_id(), remark, hostMessageLogInfo
												.getHost_tran_sn(), hostMessageLogInfo.getTeller_id(), hostMessageLogInfo.getHost_tran_date(), hostMessageLogInfo
												.getHost_tran_code(), vatFee, fee);
							} catch (RemoteException e) {
								tempErrorInfo.setErrorCode(ERR_CM_EXCEPTION_WHEN_CALL_ONECONNECT);
								tempErrorInfo.setErrorMessage(e.getMessage());
							}
							this.hostMessageLogInfo.setReceive_time(AppUtils.now(Global.DEF_FORMAT_DATE_TIME_FULL));

							hostRequestMessage = "[channel:" + hostMessageLogInfo.getRef_channel() + "," + "branchCode:" + rollout_branch_no + "," + "creditAccount:"
									+ bnfc_acct_no + "," + "creditAmount:" + amt + "," + "creditCurrency:" + bnfc_acct_ccy + "," + "creditRate:" + bnfc_sell_rate + ","
									+ "debitAccount:" + rollout_acct_no + "," + "debitAmount:" + amt + "," + "debitCurrency:" + rollout_acct_ccy + "," + "debitRate:"
									+ rollout_buy_rate + "," + "manager:" + hostMessageLogInfo.getApprover_id() + "," + "description:" + remark + "," + "sequence:"
									+ hostMessageLogInfo.getHost_tran_sn() + "," + "teller:" + hostMessageLogInfo.getTeller_id() + "," + "transDate:"
									+ hostMessageLogInfo.getHost_tran_date() + "," + "transCode:" + hostMessageLogInfo.getHost_tran_code() + "," + "vatFee:" + vatFee + ","
									+ "serviceFee:" + fee + "]";

							if (retMessage != null) {
								if (retMessage.getErrCode() != null) {
									tempErrorInfo = CachedParam.mappingErrorCode(retMessage.getErrCode(), retMessage.getDescription(), Global.MESSAGE_TYPE_ABCS);
								} else {
									tempErrorInfo = CachedParam.mappingErrorCode(String.valueOf(Global.ERR_SYSTEM_OK), Global.ERR_SYSTEM_OK_MSG, Global.MESSAGE_TYPE_ABCS);
								}
								hostResponseMessage = AppUtils.convertArrayToString(this.retMessage.getArrString());
							}
						}
					} else {// inter-bank
						if (cif_no.length() == 0) {
							tempErrorInfo.setErrorCode(Global.ERR_UDF_TRANSFER_CIF_NO_NOT_VALID_OR_MISSING);
							tempErrorInfo.setErrorMessage("ERR_UDF_TRANSFER_CIF_NO_NOT_VALID_OR_MISSING");
						}
						// TODO :Remove temporary
						// if (cert_code.length() == 0) {
						// tempErrorInfo.setErrorCode(Global.ERR_UDF_CERT_CODE_NOT_VALID_OR_MISSING);
						// tempErrorInfo.setErrorMessage("ERR_UDF_CERT_CODE_NOT_VALID_OR_MISSING");
						// }
						// // TODO :Remove temporary
						// if (rollout_acct_name.length() == 0) {
						// tempErrorInfo.setErrorCode(Global.ERR_UDF_TRANSFER_CIF_NAME_NOT_VALID_OR_MISSING);
						// tempErrorInfo.setErrorMessage("ERR_UDF_TRANSFER_CIF_NAME_NOT_VALID_OR_MISSING");
						// }

						// if (bnfc_branch_id.length() == 0) {
						// tempErrorInfo.setErrorCode(Global.ERR_UDF_TRANSFER_BANK_ID_NOT_VALID_OR_MISSING);
						// tempErrorInfo.setErrorMessage("ERR_UDF_TRANSFER_BANK_ID_NOT_VALID_OR_MISSING");
						// }

						if (GLAccount.length() == 0) {
							GLAccount = CachedParam.getSystemParam(Global.PARAM_GL_INTER_BANK_TRANSFER);
						}

						String vatFee = "0";
						String toAccount = bnfc_acct_no;
						String toName = bnfc_acct_name;// "";
						String toId = "";
						String toAddress = bnfc_bank_addr;
						String toIdIssueDate = "";
						String toIdIssuePlace = "";
						this.refTranCode = SIBS_022;
						if (tempErrorInfo.getErrorCode() == ERR_SYSTEM_OK) {
							rebuildTransactionInfo(this.refTranCode, rollout_branch_no);
							try {
								amt = CoreBankUtils.convertEB2CBNumeric(amt);
								fee = CoreBankUtils.convertEB2CBNumeric(fee);
								vatFee = CoreBankUtils.convertEB2CBNumeric(vatFee);
								String totalFee = CoreBankUtils.convertEB2CBNumeric(String.valueOf(Double.parseDouble(fee) + Double.parseDouble(vatFee)));

								String reversalDate = CoreBankUtils.convertCBDateReversal(hostMessageLogInfo.getHost_tran_date());
								String rm_ref_no = rollout_branch_no + "2" + reversalDate + AppUtils.padLeft(hostMessageLogInfo.getHost_tran_sn(), 5, '0');

								String sendMessage = buildOL2Message(hostMessageLogInfo.getWs_ip(), hostMessageLogInfo.getHost_tran_date(), rollout_branch_no, hostMessageLogInfo
										.getTeller_id(), hostMessageLogInfo.getApprover_id(), hostMessageLogInfo.getHost_tran_sn(), rm_ref_no, GLAccount, cif_no,
										rollout_acct_name, cert_code, rollout_acct_no, toAccount, toName, toId, toAddress, toIdIssueDate, toIdIssuePlace, amt, fee, vatFee,
										totalFee, remark, bnfc_branch_id, bnfc_branch_name, hostMessageLogInfo.getHost_tran_code());
								this.hostMessageLogInfo.setSend_time(AppUtils.now(Global.DEF_FORMAT_DATE_TIME_FULL));
								this.retMessage = as400Port.hostMessageSending(hostMessageLogInfo.getRef_channel(), sendMessage);
								this.hostMessageLogInfo.setReceive_time(AppUtils.now(Global.DEF_FORMAT_DATE_TIME_FULL));
							} catch (RemoteException e) {
								tempErrorInfo.setErrorCode(ERR_CM_EXCEPTION_WHEN_CALL_ONECONNECT);
								tempErrorInfo.setErrorMessage(e.getMessage());
							}
							hostRequestMessage = "[channel:" + hostMessageLogInfo.getRef_channel() + "," + "branchCode:" + rollout_branch_no + "," + "teller:"
									+ hostMessageLogInfo.getTeller_id() + "," + "approver:" + hostMessageLogInfo.getApprover_id() + "," + "core_sn:"
									+ hostMessageLogInfo.getHost_tran_sn() + "," + "tran_date:" + hostMessageLogInfo.getHost_tran_date() + "," + "rollout_acct_no:"
									+ rollout_acct_no + "," + "amt:" + amt + "," + "cif_no:" + cif_no + "," + "GLAccount:" + GLAccount + "," + "vatFee:" + vatFee + ","
									+ "Servicefee:" + fee + "," + "remark:" + remark + "," + "cif_acct_name:" + cif_acct_name + "," + "cert_code:" + cert_code + "," + "toAccount:"
									+ toAccount + "," + "toName:" + toName + "," + "toId:" + toId + "," + "toAddress:" + toAddress + "," + "toIdIssueDate:" + toIdIssueDate + ","
									+ "toIdIssuePlace:" + toIdIssuePlace + "," + "transCode:" + hostMessageLogInfo.getHost_tran_code() + "]";

							if (retMessage != null) {
								if (retMessage.getErrCode() != null) {
									tempErrorInfo = CachedParam.mappingErrorCode(retMessage.getErrCode(), retMessage.getDescription(), Global.MESSAGE_TYPE_ABCS);
								} else {
									tempErrorInfo = CachedParam.mappingErrorCode(String.valueOf(Global.ERR_SYSTEM_OK), Global.ERR_SYSTEM_OK_MSG, Global.MESSAGE_TYPE_ABCS);
								}
								hostResponseMessage = AppUtils.convertArrayToString(this.retMessage.getArrString());
							} else {

							}
						}
					}
				} else {// error
					this.retErrorInfo.setErrorCode(tempErrorInfo.getErrorCode());
					this.retErrorInfo.setErrorMessage(tempErrorInfo.getErrorMessage());
				}

				// 3.Tao tung the field
				String xmlOuputPattern = "/message/body/list[@name='records']/entity[@name='" + i + "']/?$field[set-value('%s')][?@name[set-value('%s')]]";
				ElementUtils.setXMLElementValue(outMessage, xmlOuputPattern, tran_sn, "tran_sn");
				ElementUtils.setXMLElementValue(outMessage, xmlOuputPattern, hostMessageLogInfo.getHost_tran_sn(), "core_sn");
				ElementUtils.setXMLElementValue(outMessage, xmlOuputPattern, String.valueOf(tempErrorInfo.getErrorCode()), "result");

				// Tang so luong record thanh cong
				if (tempErrorInfo.getErrorCode() == ERR_SYSTEM_OK) {
					iSuccesfulRecord += 1;
				} else {
					// ghi nhan record cuoi cung bi loi
					lastRetErrorInfo.setErrorCode(tempErrorInfo.getErrorCode());
					lastRetErrorInfo.setErrorMessage(tempErrorInfo.getErrorMessage());
				}

				this.hostMessageLogInfo.setResp_code(String.valueOf(tempErrorInfo.getErrorCode()));
				this.hostMessageLogInfo.setResp_msg(tempErrorInfo.getErrorMessage());
				this.hostMessageLogInfo.setHostRequestMsg("[" + hostRequestMessage + "]");
				this.hostMessageLogInfo.setHostResponseMsg("[" + hostResponseMessage + "]");
				this.arrRetHOSTMessageLogInfo.add((HOSTMessagLogInfo) hostMessageLogInfo.clone());

				iTotalRecord += 1;
			}// end-for

			if (iSuccesfulRecord == 0) {// all-record-fail
				this.retErrorInfo.setErrorCode(lastRetErrorInfo.getErrorCode());
				this.retErrorInfo.setErrorMessage(lastRetErrorInfo.getErrorMessage());
			} else if ((0 < iSuccesfulRecord) && (iSuccesfulRecord < iTotalRecord)) {// apart-done
				this.retErrorInfo.setErrorCode(ERR_CM_APART_OF_TRAN_SUCESSFULLY);
				this.retErrorInfo.setErrorMessage("ERR_CM_APART_OF_TRAN_SUCESSFULLY");
			} else if ((0 < iSuccesfulRecord) && (iSuccesfulRecord == iTotalRecord)) {// all-record-done
				this.retErrorInfo.setErrorCode(ERR_SYSTEM_OK);
				this.retErrorInfo.setErrorMessage("ERR_SYSTEM_OK");
			}
		} catch (Exception ex) {
			ex.printStackTrace();
			logger.error(new StringBuffer().append("Error source:").append(CLASS_NAME + ".fundTransfer()\n").append("Error message:").append(ex.toString() + "\n"));
			this.retErrorInfo.setErrorCode(Global.ERR_CM_EXCEPTION_WHEN_CALL_ONECONNECT);
			this.retErrorInfo.setErrorMessage(ex.toString());
		}
	}

	/**
	 * (OS006)Settlement for FD account
	 * 
	 * Reference :
	 * 
	 * @version 1.0
	 * @author Vu Trung Kien
	 */
	private void settlementFDAccount() {
		try {

			String xpathInput = "/message/body/field[@name='%s']";
			String receipt_branch_no = ElementUtils.getXMLElementInStringValue(inMessage, String.format(xpathInput, "receipt_branch_no"));
			String receipt_no = ElementUtils.getXMLElementInStringValue(inMessage, String.format(xpathInput, "receipt_no"));
			String receipt_ccy = ElementUtils.getXMLElementInStringValue(inMessage, String.format(xpathInput, "receipt_ccy"));
			String receipt_sell_rate = ElementUtils.getXMLElementInStringValue(inMessage, String.format(xpathInput, "receipt_sell_rate"));
			String rollin_branch_no = ElementUtils.getXMLElementInStringValue(inMessage, String.format(xpathInput, "rollin_branch_no"));
			String rollin_acc_no = ElementUtils.getXMLElementInStringValue(inMessage, String.format(xpathInput, "rollin_acc_no"));
			String rollin_acc_type = ElementUtils.getXMLElementInStringValue(inMessage, String.format(xpathInput, "rollin_acc_type"));
			String rollin_acc_ccy = ElementUtils.getXMLElementInStringValue(inMessage, String.format(xpathInput, "rollin_acc_ccy"));
			String rollin_buy_rate = ElementUtils.getXMLElementInStringValue(inMessage, String.format(xpathInput, "rollin_buy_rate"));
			String amt = CoreBankUtils.roundCBNumberic(ElementUtils.getXMLElementInStringValue(inMessage, String.format(xpathInput, "amt")));
			String fee = CoreBankUtils.roundCBNumberic(ElementUtils.getXMLElementInStringValue(inMessage, String.format(xpathInput, "fee")));
			String remark = AppUtils.convertToVietnamesNoSign(ElementUtils.getXMLElementInStringValue(inMessage, String.format(xpathInput, "remark")));

			if (receipt_branch_no.length() == 0) {
				this.retErrorInfo.setErrorCode(Global.ERR_UDF_SRC_BRANCH_CODE_NOT_VALID_OR_MISSING);
				this.retErrorInfo.setErrorMessage("ERR_UDF_SRC_BRANCH_CODE_NOT_VALID_OR_MISSING");
				return;
			}
			if (receipt_no.length() == 0) {
				this.retErrorInfo.setErrorCode(Global.ERR_UDF_FDRECEIPT_NOT_VALID_OR_MISSING);
				this.retErrorInfo.setErrorMessage("ERR_UDF_FDRECEIPT_NOT_VALID_OR_MISSING");
				return;
			}
			if (receipt_ccy.length() == 0) {
				this.retErrorInfo.setErrorCode(Global.ERR_UDF_SRC_CURRENCY_CODE_NOT_VALID_OR_MISSING);
				this.retErrorInfo.setErrorMessage("ERR_UDF_SRC_CURRENCY_CODE_NOT_VALID_OR_MISSING");
				return;
			}
			if (receipt_sell_rate.length() == 0) {
				this.retErrorInfo.setErrorCode(Global.ERR_UDF_SELL_RATE_NOT_VALID_OR_MISSING);
				this.retErrorInfo.setErrorMessage("ERR_UDF_SELL_RATE_AMOUT_NOT_VALID_OR_MISSING");
				return;
			}

			if (rollin_branch_no.length() == 0) {
				this.retErrorInfo.setErrorCode(Global.ERR_UDF_DES_BRANCH_CODE_NOT_VALID_OR_MISSING);
				this.retErrorInfo.setErrorMessage("ERR_UDF_SRC_BRANCH_CODE_NOT_VALID_OR_MISSING");
				return;
			}
			if (rollin_acc_no.length() == 0) {
				this.retErrorInfo.setErrorCode(Global.ERR_UDF_DES_BRANCH_CODE_NOT_VALID_OR_MISSING);
				this.retErrorInfo.setErrorMessage("ERR_UDF_SRC_BRANCH_CODE_NOT_VALID_OR_MISSING");
				return;
			}

			if (rollin_acc_type.length() == 0) {
				this.retErrorInfo.setErrorCode(Global.ERR_UDF_DES_ACCOUNT_TYPE_NOT_VALID_OR_MISSING);
				this.retErrorInfo.setErrorMessage("ERR_UDF_DES_ACCOUNT_TYPE_NOT_VALID_OR_MISSING");
				return;
			}
			if (rollin_acc_ccy.length() == 0) {
				this.retErrorInfo.setErrorCode(Global.ERR_UDF_DES_CURRENCY_CODE_NOT_VALID_OR_MISSING);
				this.retErrorInfo.setErrorMessage("ERR_UDF_DES_CURRENCY_CODE_NOT_VALID_OR_MISSING");
				return;
			}
			if (rollin_buy_rate.length() == 0) {
				this.retErrorInfo.setErrorCode(Global.ERR_UDF_BUY_RATE_NOT_VALID_OR_MISSING);
				this.retErrorInfo.setErrorMessage("ERR_UDF_BUY_RATE_NOT_VALID_OR_MISSING");
				return;
			}
			if (!CoreBankUtils.isValidTransactionAmount(amt)) {
				this.retErrorInfo.setErrorCode(Global.ERR_UDF_TRANSACTION_AMOUNT_NOT_VALID_OR_MISSING);
				this.retErrorInfo.setErrorMessage("ERR_UDF_TRANSACTION_AMOUT_NOT_VALID_OR_MISSING");
				return;
			}

			// 1.Lay thong tin ve fdreceipt
			// int startPos = 67;
			// int recordLength = 50;
			// rebuildTransactionInfo(Global.SIBS_005,
			// Global.APP_DEFAULT_BRANCH_CODE);
			// MBASE_TEMPLATE[2] = hostMessageLogInfo.getWs_ip();
			// MBASE_TEMPLATE[25] = hostMessageLogInfo.getTeller_id();
			// MBASE_TEMPLATE[26] = hostMessageLogInfo.getWs_name();
			// MBASE_TEMPLATE[32] = hostMessageLogInfo.getApprover_id();
			// MBASE_TEMPLATE[40] = hostMessageLogInfo.getWs_name();
			// MBASE_TEMPLATE[42] = hostMessageLogInfo.getBranch_code();
			// MBASE_TEMPLATE[18] = "BBMBSCDINQFNC";// scenarioNumber
			// MBASE_TEMPLATE[27] =
			// this.hostMessageLogInfo.getHost_tran_code();// "36501";
			// MBASE_TEMPLATE[46] =
			// this.hostMessageLogInfo.getHost_tran_code();// "36501";
			// MBASE_TEMPLATE[64] = receipt_no;
			// MBASE_TEMPLATE[68] = receipt_no;
			// MBASE_TEMPLATE[65] = Global.COREBBANK_FD_RECEIPT_ACCOUNT_TYPE;
			// MBASE_TEMPLATE[69] = Global.COREBBANK_FD_RECEIPT_ACCOUNT_TYPE;
			//
			// String hostSendMessage =
			// AppUtils.convertArrayToString(MBASE_TEMPLATE);
			// String hostReceiveMessage = "";
			// String serial = "";
			// this.hostMessageLogInfo.setSend_time(AppUtils.now(Global.DEF_FORMAT_DATE_TIME_FULL));
			// try {
			// retMessage =
			// as400Port.hostMessageSending(hostMessageLogInfo.getRef_channel(),
			// hostSendMessage);
			// } catch (RemoteException ex) {
			// this.retErrorInfo.setErrorCode(Global.ERR_CM_EXCEPTION_WHEN_CALL_ONECONNECT);
			// this.retErrorInfo.setErrorMessage(ex.toString());
			// }
			// ArrayList<String[]> retArrOfResult = null;
			// this.hostMessageLogInfo.setReceive_time(AppUtils.now(Global.DEF_FORMAT_DATE_TIME_FULL));
			// hostResponseMessage =
			// AppUtils.convertArrayToString(retMessage.getArrString());
			// if (retMessage != null) {
			// if (retMessage.getErrCode() == null) {
			// retArrOfResult =
			// AppUtils.getListOfResponseRow(retMessage.getArrString(),
			// startPos, recordLength);
			// if (retArrOfResult.size() > 0) {
			// serial = (String) retArrOfResult.get(0)[10];
			// }
			// } else {
			// this.retErrorInfo.setErrorCode(Global.ERR_MBASE_START);
			// this.retErrorInfo.setErrorMessage(retMessage.getDescription());
			// }
			// }
			//
			// this.hostMessageLogInfo.setResp_code(String.valueOf(retErrorInfo.getErrorCode()));
			// this.hostMessageLogInfo.setResp_msg(retErrorInfo.getErrorMessage());
			// this.hostMessageLogInfo.setHostRequestMsg("[" + hostSendMessage +
			// "]");
			// this.hostMessageLogInfo.setHostResponseMsg("[" +
			// hostReceiveMessage + "]");
			// this.arrRetHOSTMessageLogInfo.add(hostMessageLogInfo);

			// Kienvt lay thong tin ve fd receipt
			AccountInfoFacade acctFacade = new AccountInfoFacade();
			AccountInfo acctInfo = acctFacade.getAccountInfoByAccountNo(receipt_no, COREBBANK_FD_RECEIPT_ACCOUNT_TYPE);

			String serial = acctInfo.getPassbook_no();
			if (!amt.equals(acctInfo.getCurrent_cash_value())) {
				amt = acctInfo.getCurrent_cash_value();
				// amt = String.valueOf((double)
				// java.lang.Math.round((Double.valueOf(amt))));
			}

			// 2.Settlement
			rebuildTransactionInfo(SIBS_016, receipt_branch_no);
			ABCS_TEMPLATE[2] = hostMessageLogInfo.getWs_ip();
			ABCS_TEMPLATE[18] = "BBHTLMONEYFNC";
			ABCS_TEMPLATE[25] = hostMessageLogInfo.getTeller_id();
			ABCS_TEMPLATE[26] = hostMessageLogInfo.getWs_name();
			ABCS_TEMPLATE[34] = hostMessageLogInfo.getWs_ip();
			ABCS_TEMPLATE[42] = hostMessageLogInfo.getTeller_id();
			ABCS_TEMPLATE[43] = hostMessageLogInfo.getHost_tran_sn();
			ABCS_TEMPLATE[49] = hostMessageLogInfo.getHost_tran_date();
			ABCS_TEMPLATE[53] = hostMessageLogInfo.getApprover_id();
			ABCS_TEMPLATE[27] = hostMessageLogInfo.getHost_tran_code(); // hostTranCode;
			ABCS_TEMPLATE[48] = hostMessageLogInfo.getHost_tran_code(); // hostTranCode;

			// "00000000000";
			fee = "0";// Kienvt dump
			double dblInputFee = Double.parseDouble(fee);
			double dblVATCharge = dblInputFee / Double.parseDouble(Global.BASED_VAT_RATE);

			ABCS_TEMPLATE[54] = rollin_branch_no;
			ABCS_TEMPLATE[66] = CoreBankUtils.convertEB2CBNumeric(amt);
			ABCS_TEMPLATE[69] = receipt_no;
			ABCS_TEMPLATE[72] = rollin_acc_no;
			ABCS_TEMPLATE[81] = CoreBankUtils.convertEB2CBNumeric(String.valueOf(dblInputFee + dblVATCharge));

			ABCS_TEMPLATE[88] = CoreBankUtils.convertEB2CBNumeric(rollin_buy_rate);
			ABCS_TEMPLATE[89] = CoreBankUtils.convertEB2CBNumeric(rollin_buy_rate);
			ABCS_TEMPLATE[90] = CoreBankUtils.convertEB2CBNumeric(receipt_sell_rate);
			ABCS_TEMPLATE[91] = CoreBankUtils.convertEB2CBNumeric(receipt_sell_rate);

			ABCS_TEMPLATE[83] = CoreBankUtils.convertEB2CBNumeric(amt);
			ABCS_TEMPLATE[84] = serial;// "00000000000";// serial

			ABCS_TEMPLATE[94] = Global.BASED_CCYCD;
			ABCS_TEMPLATE[106] = receipt_ccy;
			ABCS_TEMPLATE[107] = receipt_ccy;
			ABCS_TEMPLATE[108] = rollin_acc_ccy;
			ABCS_TEMPLATE[109] = rollin_acc_ccy;

			ABCS_TEMPLATE[236] = rollin_acc_no;
			ABCS_TEMPLATE[238] = CoreBankUtils.convertEB2CBNumeric(String.valueOf(dblInputFee + dblVATCharge));

			ABCS_TEMPLATE[241] = CoreBankUtils.convertEB2CBNumeric(fee);
			ABCS_TEMPLATE[242] = CoreBankUtils.convertEB2CBNumeric(String.valueOf(dblVATCharge));
			ABCS_TEMPLATE[250] = CoreBankUtils.convertEB2CBNumeric(amt);
			ABCS_TEMPLATE[281] = remark;

			this.hostRequestMessage = AppUtils.convertArrayToString(ABCS_TEMPLATE);

			this.hostMessageLogInfo.setSend_time(AppUtils.now(Global.DEF_FORMAT_DATE_TIME_FULL));
			try {
				retMessage = as400Port.hostMessageSending(hostMessageLogInfo.getRef_channel(), hostRequestMessage);
			} catch (RemoteException ex) {
				this.retErrorInfo.setErrorCode(Global.ERR_CM_EXCEPTION_WHEN_CALL_ONECONNECT);
				this.retErrorInfo.setErrorMessage(ex.toString());
			}
			this.hostMessageLogInfo.setReceive_time(AppUtils.now(Global.DEF_FORMAT_DATE_TIME_FULL));

			if (retMessage != null) {
				if (retMessage.getErrCode() != null) {
					this.retErrorInfo = CachedParam.mappingErrorCode(retMessage.getErrCode(), retMessage.getDescription(), Global.MESSAGE_TYPE_ABCS);
				} else {
					this.retErrorInfo = CachedParam.mappingErrorCode(String.valueOf(Global.ERR_SYSTEM_OK), Global.ERR_SYSTEM_OK_MSG, Global.MESSAGE_TYPE_ABCS);
				}
				this.hostResponseMessage = AppUtils.convertArrayToString(this.retMessage.getArrString());
			} else {

			}
			this.hostMessageLogInfo.setResp_code(String.valueOf(retErrorInfo.getErrorCode()));
			this.hostMessageLogInfo.setResp_msg(retErrorInfo.getErrorMessage());
			this.hostMessageLogInfo.setHostRequestMsg("[" + hostRequestMessage + "]");
			this.hostMessageLogInfo.setHostResponseMsg("[" + hostResponseMessage + "]");
			this.arrRetHOSTMessageLogInfo.add(hostMessageLogInfo);
		} catch (Exception ex) {
			ex.printStackTrace();
			logger.error(new StringBuffer().append("Error source:").append(CLASS_NAME + ".settlementFDAccount()\n").append("Error message:").append(ex.toString() + "\n"));
			this.retErrorInfo.setErrorCode(Global.ERR_SYSTEM_UNKNOWN_ERROR);
			this.retErrorInfo.setErrorMessage(ex.toString());
		}
	}

	/**
	 * (OS004)Transfer money to FD receipt(Only transfer from CA account)
	 * 
	 * Reference: SIBS_033
	 * 
	 * @version 1.0
	 * @author Vu Trung Kien
	 */
	private void transferToFDReceipt() {
		try {

			String xpathInput = "/message/body/field[@name='%s']";
			String receipt_branch_no = ElementUtils.getXMLElementInStringValue(inMessage, String.format(xpathInput, "receipt_branch_no"));
			String receipt_no = ElementUtils.getXMLElementInStringValue(inMessage, String.format(xpathInput, "receipt_no"));
			String receipt_ccy = ElementUtils.getXMLElementInStringValue(inMessage, String.format(xpathInput, "receipt_ccy"));
			String receipt_sell_rate = ElementUtils.getXMLElementInStringValue(inMessage, String.format(xpathInput, "receipt_sell_rate"));
			String rollout_branch_no = ElementUtils.getXMLElementInStringValue(inMessage, String.format(xpathInput, "rollout_branch_no"));
			String rollout_acct_no = ElementUtils.getXMLElementInStringValue(inMessage, String.format(xpathInput, "rollout_acct_no"));
			String rollout_acct_ccy = ElementUtils.getXMLElementInStringValue(inMessage, String.format(xpathInput, "rollout_acct_ccy"));
			String rollout_acct_type = ElementUtils.getXMLElementInStringValue(inMessage, String.format(xpathInput, "rollout_acct_type"));
			String rollout_buy_rate = ElementUtils.getXMLElementInStringValue(inMessage, String.format(xpathInput, "rollout_buy_rate"));
			String amt = CoreBankUtils.roundCBNumberic(ElementUtils.getXMLElementInStringValue(inMessage, String.format(xpathInput, "amt")));
			String fee = CoreBankUtils.roundCBNumberic(ElementUtils.getXMLElementInStringValue(inMessage, String.format(xpathInput, "fee")));
			String remark = AppUtils.convertToVietnamesNoSign(ElementUtils.getXMLElementInStringValue(inMessage, String.format(xpathInput, "remark")));

			if (receipt_branch_no.length() == 0) {
				this.retErrorInfo.setErrorCode(Global.ERR_UDF_SRC_BRANCH_CODE_NOT_VALID_OR_MISSING);
				this.retErrorInfo.setErrorMessage("ERR_UDF_SRC_BRANCH_CODE_NOT_VALID_OR_MISSING");
				return;
			}
			if (receipt_no.length() == 0) {
				this.retErrorInfo.setErrorCode(Global.ERR_UDF_FDRECEIPT_NOT_VALID_OR_MISSING);
				this.retErrorInfo.setErrorMessage("ERR_UDF_FDRECEIPT_NOT_VALID_OR_MISSING");
				return;
			}
			if (receipt_ccy.length() == 0) {
				this.retErrorInfo.setErrorCode(Global.ERR_UDF_SRC_CURRENCY_CODE_NOT_VALID_OR_MISSING);
				this.retErrorInfo.setErrorMessage("ERR_UDF_SRC_CURRENCY_CODE_NOT_VALID_OR_MISSING");
				return;
			}
			if (receipt_sell_rate.length() == 0) {
				this.retErrorInfo.setErrorCode(Global.ERR_UDF_SELL_RATE_NOT_VALID_OR_MISSING);
				this.retErrorInfo.setErrorMessage("ERR_UDF_SELL_RATE_AMOUT_NOT_VALID_OR_MISSING");
				return;
			}

			if (rollout_branch_no.length() == 0) {
				this.retErrorInfo.setErrorCode(Global.ERR_UDF_DES_BRANCH_CODE_NOT_VALID_OR_MISSING);
				this.retErrorInfo.setErrorMessage("ERR_UDF_SRC_BRANCH_CODE_NOT_VALID_OR_MISSING");
				return;
			}
			if (rollout_acct_no.length() == 0) {
				this.retErrorInfo.setErrorCode(Global.ERR_UDF_DES_BRANCH_CODE_NOT_VALID_OR_MISSING);
				this.retErrorInfo.setErrorMessage("ERR_UDF_SRC_BRANCH_CODE_NOT_VALID_OR_MISSING");
				return;
			}

			if (rollout_acct_ccy.length() == 0) {
				this.retErrorInfo.setErrorCode(Global.ERR_UDF_TRANSACTION_AMOUNT_NOT_VALID_OR_MISSING);
				this.retErrorInfo.setErrorMessage("ERR_UDF_TRANSACTION_AMOUT_NOT_VALID_OR_MISSING");
				return;
			}
			if (rollout_acct_type.length() == 0 || CoreBankUtils.isValidAccountType(rollout_acct_type) == false) {
				this.retErrorInfo.setErrorCode(Global.ERR_UDF_DES_ACCOUNT_TYPE_NOT_VALID_OR_MISSING);
				this.retErrorInfo.setErrorMessage("ERR_UDF_DES_ACCOUNT_TYPE_NOT_VALID_OR_MISSING");
				return;
			}
			if (rollout_buy_rate.length() == 0) {
				this.retErrorInfo.setErrorCode(Global.ERR_UDF_BUY_RATE_NOT_VALID_OR_MISSING);
				this.retErrorInfo.setErrorMessage("ERR_UDF_BUY_RATE_NOT_VALID_OR_MISSING");
				return;
			}
			if (!CoreBankUtils.isValidTransactionAmount(amt)) {
				this.retErrorInfo.setErrorCode(Global.ERR_UDF_TRANSACTION_AMOUNT_NOT_VALID_OR_MISSING);
				this.retErrorInfo.setErrorMessage("ERR_UDF_TRANSACTION_AMOUT_NOT_VALID_OR_MISSING");
				return;
			}
			rebuildTransactionInfo(SIBS_017, receipt_branch_no);

			ABCS_TEMPLATE[2] = hostMessageLogInfo.getWs_ip();
			ABCS_TEMPLATE[18] = "BBHTLMONEYFNC";
			ABCS_TEMPLATE[25] = hostMessageLogInfo.getTeller_id();
			ABCS_TEMPLATE[26] = hostMessageLogInfo.getWs_name();
			ABCS_TEMPLATE[34] = hostMessageLogInfo.getWs_ip();
			ABCS_TEMPLATE[42] = hostMessageLogInfo.getTeller_id();
			ABCS_TEMPLATE[43] = hostMessageLogInfo.getHost_tran_sn();
			ABCS_TEMPLATE[49] = hostMessageLogInfo.getHost_tran_date();
			ABCS_TEMPLATE[53] = hostMessageLogInfo.getApprover_id();
			ABCS_TEMPLATE[27] = hostMessageLogInfo.getHost_tran_code();// hostTranCode;
			ABCS_TEMPLATE[48] = hostMessageLogInfo.getHost_tran_code();

			// dump value
			ABCS_TEMPLATE[113] = "3";
			ABCS_TEMPLATE[127] = "1";
			ABCS_TEMPLATE[129] = "4";
			ABCS_TEMPLATE[130] = "2";
			ABCS_TEMPLATE[143] = "4";
			ABCS_TEMPLATE[144] = "4";
			ABCS_TEMPLATE[145] = "4";
			ABCS_TEMPLATE[151] = "1";
			ABCS_TEMPLATE[256] = "4";
			ABCS_TEMPLATE[257] = "4";
			ABCS_TEMPLATE[258] = "4";
			ABCS_TEMPLATE[265] = "2";
			ABCS_TEMPLATE[296] = "1";
			ABCS_TEMPLATE[297] = "1";

			double dblInputFee = Double.parseDouble(fee);
			double dblVATCharge = dblInputFee / Double.parseDouble(Global.BASED_VAT_RATE);

			ABCS_TEMPLATE[54] = receipt_branch_no;
			ABCS_TEMPLATE[66] = CoreBankUtils.convertEB2CBNumeric(amt);
			ABCS_TEMPLATE[69] = receipt_no;
			ABCS_TEMPLATE[72] = rollout_acct_no;
			ABCS_TEMPLATE[83] = CoreBankUtils.convertEB2CBNumeric(amt);
			ABCS_TEMPLATE[88] = rollout_buy_rate;
			ABCS_TEMPLATE[89] = receipt_sell_rate;
			ABCS_TEMPLATE[90] = rollout_buy_rate;
			ABCS_TEMPLATE[91] = rollout_buy_rate;
			ABCS_TEMPLATE[94] = Global.BASED_CCYCD;
			ABCS_TEMPLATE[106] = receipt_ccy;
			ABCS_TEMPLATE[107] = receipt_ccy;
			ABCS_TEMPLATE[108] = rollout_acct_ccy;
			ABCS_TEMPLATE[109] = rollout_acct_ccy;
			ABCS_TEMPLATE[241] = CoreBankUtils.convertEB2CBNumeric(fee);
			ABCS_TEMPLATE[242] = CoreBankUtils.convertEB2CBNumeric(String.valueOf(dblVATCharge));
			ABCS_TEMPLATE[250] = CoreBankUtils.convertEB2CBNumeric(amt);
			ABCS_TEMPLATE[281] = remark;

			String hostSendMessage = AppUtils.convertArrayToString(ABCS_TEMPLATE);
			String hostReceiveMessage = "";

			this.hostMessageLogInfo.setSend_time(AppUtils.now(Global.DEF_FORMAT_DATE_TIME_FULL));
			try {
				retMessage = as400Port.hostMessageSending(hostMessageLogInfo.getRef_channel(), hostSendMessage);
			} catch (RemoteException ex) {
				this.retErrorInfo.setErrorCode(Global.ERR_CM_EXCEPTION_WHEN_CALL_ONECONNECT);
				this.retErrorInfo.setErrorMessage(ex.toString());
			}
			this.hostMessageLogInfo.setReceive_time(AppUtils.now(Global.DEF_FORMAT_DATE_TIME_FULL));

			if (retMessage != null) {
				if (retMessage.getErrCode() != null) {
					this.retErrorInfo = CachedParam.mappingErrorCode(retMessage.getErrCode(), retMessage.getDescription(), Global.MESSAGE_TYPE_ABCS);
				} else {
					this.retErrorInfo = CachedParam.mappingErrorCode(String.valueOf(Global.ERR_SYSTEM_OK), Global.ERR_SYSTEM_OK_MSG, Global.MESSAGE_TYPE_ABCS);
				}
				hostReceiveMessage = AppUtils.convertArrayToString(this.retMessage.getArrString());
			} else {

			}
			this.hostMessageLogInfo.setResp_code(String.valueOf(retErrorInfo.getErrorCode()));
			this.hostMessageLogInfo.setResp_msg(retErrorInfo.getErrorMessage());
			this.hostMessageLogInfo.setHostRequestMsg("[" + hostSendMessage + "]");
			this.hostMessageLogInfo.setHostResponseMsg("[" + hostReceiveMessage + "]");
			this.arrRetHOSTMessageLogInfo.add(hostMessageLogInfo);

		} catch (Exception ex) {
			ex.printStackTrace();
			logger.error(new StringBuffer().append("Error source:").append(CLASS_NAME + ".transferToFDReceipt()\n").append("Error message:").append(ex.toString() + "\n"));
			this.retErrorInfo.setErrorCode(Global.ERR_CM_EXCEPTION_WHEN_CALL_ONECONNECT);
			this.retErrorInfo.setErrorMessage(ex.toString());
		}
	}

	/**
	 * (FX002)Exchange money
	 * 
	 * @version 1.0
	 * @author Vu Trung Kien
	 */
	private void exchangeMoney() {
		try {

			String xmlInputPattern = "/message/body/field[@name='%s']";
			String sell_branch_no = ElementUtils.getXMLElementInStringValue(inMessage, String.format(xmlInputPattern, "sell_branch_no"));
			String sell_acct_no = ElementUtils.getXMLElementInStringValue(inMessage, String.format(xmlInputPattern, "sell_acct_no"));
			String sell_ccy = ElementUtils.getXMLElementInStringValue(inMessage, String.format(xmlInputPattern, "sell_ccy"));
			String receipt_branch_no = ElementUtils.getXMLElementInStringValue(inMessage, String.format(xmlInputPattern, "receipt_branch_no"));
			String receipt_acct_no = ElementUtils.getXMLElementInStringValue(inMessage, String.format(xmlInputPattern, "receipt_acct_no"));
			String receipt_ccy = ElementUtils.getXMLElementInStringValue(inMessage, String.format(xmlInputPattern, "receipt_ccy"));
			String amt = CoreBankUtils.roundCBNumberic(ElementUtils.getXMLElementInStringValue(inMessage, String.format(xmlInputPattern, "amt")));
			String fx_rate = CoreBankUtils.roundCBNumberic(ElementUtils.getXMLElementInStringValue(inMessage, String.format(xmlInputPattern, "fx_rate")));

			if (sell_branch_no.length() == 0) {
				this.retErrorInfo.setErrorCode(Global.ERR_UDF_SRC_BRANCH_CODE_NOT_VALID_OR_MISSING);
				this.retErrorInfo.setErrorMessage("ERR_UDF_SRC_BRANCH_CODE_NOT_VALID_OR_MISSING");
				return;
			}
			if (sell_acct_no.length() == 0) {
				this.retErrorInfo.setErrorCode(Global.ERR_UDF_SRC_ACCOUNT_NO_NOT_VALID_OR_MISSING);
				this.retErrorInfo.setErrorMessage("ERR_UDF_SRC_ACCOUNT_NO_NOT_VALID_OR_MISSING");
				return;
			}
			if (sell_ccy.length() == 0) {
				this.retErrorInfo.setErrorCode(Global.ERR_UDF_SRC_CURRENCY_CODE_NOT_VALID_OR_MISSING);
				this.retErrorInfo.setErrorMessage("ERR_UDF_SRC_CURRENCY_CODE_NOT_VALID_OR_MISSING");
				return;
			}
			if (fx_rate.length() == 0) {
				this.retErrorInfo.setErrorCode(Global.ERR_UDF_SELL_RATE_NOT_VALID_OR_MISSING);
				this.retErrorInfo.setErrorMessage("ERR_UDF_SELL_RATE_NOT_VALID_OR_MISSING");
				return;
			}
			if (receipt_branch_no.length() == 0) {
				this.retErrorInfo.setErrorCode(Global.ERR_UDF_DES_BRANCH_CODE_NOT_VALID_OR_MISSING);
				this.retErrorInfo.setErrorMessage("ERR_UDF_DES_BRANCH_CODE_NOT_VALID_OR_MISSING");
				return;
			}
			if (receipt_acct_no.length() == 0) {
				this.retErrorInfo.setErrorCode(Global.ERR_UDF_DES_ACCOUNT_NO_NOT_VALID_OR_MISSING);
				this.retErrorInfo.setErrorMessage("ERR_UDF_DES_ACCOUNT_NO_NOT_VALID_OR_MISSING");
				return;
			}
			if (receipt_ccy.length() == 0) {
				this.retErrorInfo.setErrorCode(Global.ERR_UDF_DES_CURRENCY_CODE_NOT_VALID_OR_MISSING);
				this.retErrorInfo.setErrorMessage("ERR_UDF_DES_CURRENCY_CODE_NOT_VALID_OR_MISSING");
				return;
			}

			if (!CoreBankUtils.isValidTransactionAmount(amt)) {
				this.retErrorInfo.setErrorCode(Global.ERR_UDF_TRANSACTION_AMOUNT_NOT_VALID_OR_MISSING);
				this.retErrorInfo.setErrorMessage("ERR_UDF_TRANSACTION_AMOUNT_NOT_VALID_OR_MISSING");
				return;
			}
			if (!CoreBankUtils.isValidTransactionAmount(fx_rate)) {
				this.retErrorInfo.setErrorCode(Global.ERR_UDF_TRANSACTION_AMOUNT_NOT_VALID_OR_MISSING);
				this.retErrorInfo.setErrorMessage("ERR_UDF_TRANSACTION_AMOUNT_NOT_VALID_OR_MISSING");
				return;
			}
			amt = String.valueOf(AppUtils.isValidNumber(amt) == true ? amt : "0");
			fx_rate = String.valueOf(AppUtils.isValidNumber(fx_rate) == true ? fx_rate : "0");
			// String hostTranCode = "";
			if (sell_branch_no.equals(receipt_branch_no)) {
				rebuildTransactionInfo(SIBS_025, receipt_branch_no);
			} else {
				rebuildTransactionInfo(SIBS_026, receipt_branch_no);
			}
			String totalAMT = String.valueOf(java.lang.Math.round(Double.valueOf(amt) * java.lang.Math.round(Double.valueOf(fx_rate)))) + "00";
			ABCS_TEMPLATE[2] = hostMessageLogInfo.getWs_ip();
			ABCS_TEMPLATE[18] = "BBHTLMONEYFNC";
			ABCS_TEMPLATE[25] = hostMessageLogInfo.getTeller_id();
			ABCS_TEMPLATE[26] = hostMessageLogInfo.getWs_name();
			ABCS_TEMPLATE[27] = hostMessageLogInfo.getHost_tran_code();
			ABCS_TEMPLATE[34] = hostMessageLogInfo.getWs_ip();
			ABCS_TEMPLATE[42] = hostMessageLogInfo.getTeller_id();
			ABCS_TEMPLATE[43] = hostMessageLogInfo.getHost_tran_sn();
			ABCS_TEMPLATE[48] = hostMessageLogInfo.getHost_tran_code();//
			ABCS_TEMPLATE[49] = hostMessageLogInfo.getHost_tran_date();
			ABCS_TEMPLATE[53] = hostMessageLogInfo.getApprover_id();
			ABCS_TEMPLATE[54] = sell_branch_no;
			ABCS_TEMPLATE[64] = sell_acct_no;
			ABCS_TEMPLATE[66] = totalAMT;
			ABCS_TEMPLATE[72] = receipt_acct_no;
			ABCS_TEMPLATE[83] = CoreBankUtils.convertEB2CBNumeric(amt);
			ABCS_TEMPLATE[88] = CoreBankUtils.convertEB2CBNumeric(fx_rate);

			ABCS_TEMPLATE[80] = "000";
			ABCS_TEMPLATE[81] = "000";
			ABCS_TEMPLATE[82] = "000";
			ABCS_TEMPLATE[113] = "3";
			ABCS_TEMPLATE[127] = "1";
			ABCS_TEMPLATE[128] = "4";
			ABCS_TEMPLATE[129] = "4";
			ABCS_TEMPLATE[130] = "2";
			ABCS_TEMPLATE[143] = "4";
			ABCS_TEMPLATE[144] = "4";
			ABCS_TEMPLATE[145] = "4";
			ABCS_TEMPLATE[148] = "5";
			ABCS_TEMPLATE[151] = "1";
			ABCS_TEMPLATE[239] = "000";
			ABCS_TEMPLATE[241] = "000";
			ABCS_TEMPLATE[242] = "000";
			ABCS_TEMPLATE[243] = "000";
			ABCS_TEMPLATE[254] = "5";
			ABCS_TEMPLATE[256] = "4";
			ABCS_TEMPLATE[257] = "4";
			ABCS_TEMPLATE[258] = "4";

			ABCS_TEMPLATE[89] = BASED_CCYCD_RATE;
			ABCS_TEMPLATE[94] = BASED_CCYCD;
			ABCS_TEMPLATE[106] = sell_ccy;
			ABCS_TEMPLATE[107] = receipt_ccy;
			ABCS_TEMPLATE[108] = receipt_ccy;
			ABCS_TEMPLATE[109] = receipt_ccy;
			ABCS_TEMPLATE[285] = totalAMT;
			ABCS_TEMPLATE[286] = "000";
			ABCS_TEMPLATE[287] = "000";
			ABCS_TEMPLATE[295] = "3";
			ABCS_TEMPLATE[296] = "1";
			ABCS_TEMPLATE[297] = "1";

			String hostSendMessage = AppUtils.convertArrayToString(ABCS_TEMPLATE);
			String hostReceiveMessage = "";
			this.hostMessageLogInfo.setSend_time(AppUtils.now(Global.DEF_FORMAT_DATE_TIME_FULL));
			this.retMessage = as400Port.hostMessageSending(hostMessageLogInfo.getRef_channel(), hostSendMessage);
			this.hostMessageLogInfo.setReceive_time(AppUtils.now(Global.DEF_FORMAT_DATE_TIME_FULL));
			if (retMessage != null) {
				hostReceiveMessage = AppUtils.convertArrayToString(retMessage.getArrString());
				if (retMessage.getErrCode() == null) {
				} else {
					this.retErrorInfo.setErrorCode(Global.ERR_MBASE_START);
					this.retErrorInfo.setErrorMessage(retMessage.getDescription());
				}
			}
			this.hostMessageLogInfo.setResp_code(String.valueOf(retErrorInfo.getErrorCode()));
			this.hostMessageLogInfo.setResp_msg(retErrorInfo.getErrorMessage());
			this.hostMessageLogInfo.setHostRequestMsg("[" + hostSendMessage + "]");
			this.hostMessageLogInfo.setHostResponseMsg("[" + hostReceiveMessage + "]");
			this.arrRetHOSTMessageLogInfo.add(hostMessageLogInfo);
		} catch (Exception ex) {
			ex.printStackTrace();
			logger.error(new StringBuffer().append("Error source:").append(CLASS_NAME + ".exchangeMoney()\n").append("Error message:").append(ex.toString() + "\n"));
			this.retErrorInfo.setErrorCode(Global.ERR_SYSTEM_UNKNOWN_ERROR);
			this.retErrorInfo.setErrorMessage(ex.toString());
		}
	}

	// TODO: Chi cho chuyen tien viet nam dong
	private String buildOL2Message(String hostIP, String transactionDate, String branchCode, String tellerId, String approverId, String refId, String rm_ref_no, String glAccount,
			String fromCif, String fromName, String fromId, String fromAccount, String toAccount, String toName, String toId, String toAddress, String toIdIssueDate,
			String toIdIssuePlace, String amount, String serviceFee, String vatFee, String totalFee, String remarks, String bank_id, String bank_name, String tranCode) {

		// Kiem tra length cat bot cac ky tu thua cua cac truong co trong phan
		// remark
		fromName = AppUtils.subStringBySpecLength(fromName, 41);
		toId = AppUtils.subStringBySpecLength(toId, 196);
		glAccount = AppUtils.subStringBySpecLength(glAccount, 19);
		toName = AppUtils.subStringBySpecLength(toName, 40);
		bank_id = AppUtils.subStringBySpecLength(bank_id, 43);
		bank_name = AppUtils.subStringBySpecLength(bank_name, 40);
		toAccount = AppUtils.subStringBySpecLength(toAccount, 20);
		toAddress = AppUtils.subStringBySpecLength(toAddress, 113);
		toIdIssueDate = AppUtils.subStringBySpecLength(toIdIssueDate, 144);

		String message = "*LINX|" + hostIP + "||||213|42|0200||ABCS|*LINX||" + "|||||BBHTLMONEYFNC|||||||" + tellerId + "|al|" + tranCode + "||||3843|*MOSA|" + "|" + hostIP
				+ "|||||T9999|||" + tellerId + "|" + refId + "|N||||" + tranCode + "|" + transactionDate + "||VD|al|" + approverId + "|" + branchCode + "|0|1|N|N|N|N|N|N|N|"
				+ rm_ref_no + "||" + (amount) + "|||||" + AppUtils.padLeft(glAccount, 19, '0') + "|" + fromAccount + "|||" + "||||||" + totalFee + "||" + amount
				+ "||||||10000000|10000000||10000000||VND|" + fromCif + "|||||" + "||||||VND|VND|VND|VND|||||||||||||||||||||||||||||||||||||||||||||||||||"
				+ "||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||VND||||||||||||||" + fromAccount + "||" + totalFee + "|||" + serviceFee + "|" + vatFee
				+ "||||||||" + amount + "||||||||||||||||||||||||||||||" + "|" + remarks + "||||||||||||||||||||||";

		message += "RM        " + "C                            "
				+ "OL2                                                                                                                 " + AppUtils.padRight("", 60, ' ')
				+ "SMSBK       " + "VND                                                  " + AppUtils.padRight("C" + fromName.toUpperCase(), 41, ' ')
				+ AppUtils.padRight(toId, 196, ' ') + "T" + AppUtils.padLeft(glAccount, 19, '0') + AppUtils.padRight(toAccount.toUpperCase(), 20, ' ')
				+ AppUtils.padRight(toName.toUpperCase(), 40, ' ') + AppUtils.padRight(bank_id, 43, ' ') // bnfc_bank_id
				+ AppUtils.padRight(bank_name, 40, ' ') + AppUtils.padRight(toAddress, 113, ' ') + "0000000000000000000      " + AppUtils.padLeft(String.valueOf(amount), 54, '0') // amt
				+ "            " + toIdIssueDate + AppUtils.padRight("", 144, ' ') + "|";

		return message;
	}
}
